This repository has been archived by the owner on Jun 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dom.js
52 lines (50 loc) · 1.64 KB
/
dom.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
52
/* global document */
const submitFormAndWait = (page, selectors, submitForm, waitForPageLoad) =>
submitForm
? page
.evaluateHandle(firstInput => {
const form = document.querySelector(firstInput).form;
const submitButton = form.querySelector('[type="submit"]');
if (submitButton) {
// submitButton.click();
return submitButton;
} else {
const input = form.querySelector('input[type="text"]');
if (input) {
return input;
}
const password = form.querySelector('input[type="password"]');
if (password) {
return password;
}
return "nothing";
}
}, selectors[0])
.then(async result => {
return result
.getProperty("type")
.then(property => property.jsonValue())
.then(type => {
if (type === "submit") {
return Promise.all([
waitForPageLoad
? page.waitForNavigation({
waitUntil: "networkidle0"
})
: page.waitFor(200),
result
.asElement()
.click()
.then(() => result.dispose())
]);
} else if (waitForPageLoad) {
// eslint-disable-next-line no-console
console.warn("Warning: found no way to submit the form");
}
return null;
});
})
: page.waitFor(200);
module.exports = {
submitFormAndWait
};