-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
44 lines (38 loc) · 1.04 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
const clearTextField = async (page, selector) => {
await page.evaluate(selector => {
document.querySelector(selector).value = "";
}, selector);
};
const getElementInnerText = async (element) => {
const text = await element.evaluate(node => node.innerText);
return text;
};
const queryElement = async (node, selector) => {
let res = node.evaluate(el => {
let res = document.querySelector(selector);
return res;
});
return res;
};
const type = async (element, text) => {
await element.focus();
await element.type(text, { delay: 50 });
};
const click = async (element, count) => {
await element.click({clickCount: count})
};
const navigateClick = async (page, element, navSelector, opts=false) => {
await Promise.all([
element.click(),
page.waitForNavigation(),
navSelector ? page.waitForSelector(navSelector, {visible: opts}) : null
])
};
module.exports = {
clearTextField,
getElementInnerText,
queryElement,
type,
navigateClick,
click
};