-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
51 lines (49 loc) · 1.48 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
exports.isVisible = async function(page, selector) {
await page.$eval(selector, elem => {
return (
window.getComputedStyle(elem).getPropertyValue("display") !== "none" &&
elem.offsetHeight
);
});
return false;
};
exports.dropdownSelect = async function(page, selector, value) {
await page.click(selector);
await page.waitForSelector(selector + " ul.dnn-dropdown-options");
switch (typeof value) {
case "string":
const options = await page.$$(selector + " li.dnn-dropdown-option");
for (var i = 0; i < options.length; i++) {
let option = options[i];
let text = await page.evaluate(option => option.textContent, option);
if (text == value) {
await option.click();
await page.waitFor(500);
}
}
break;
case "number":
await page.click(
selector + " li.dnn-dropdown-option:nth-child(" + value.toString() + ")"
);
break;
}
};
Object.prototype.getPath = function(childName) {
if (this.path === undefined) return undefined;
var path = this.path === undefined ? "" : this.path;
if (this[childName]) {
if (typeof this[childName] === "string") {
return path + this[childName];
} else {
return path + this[childName].path;
}
}
for (var property in this) {
if (this.hasOwnProperty(property)) {
let childPath = this[property].getPath(childName);
if (childPath !== undefined) return path + childPath;
}
}
return undefined;
};