-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpups.js
68 lines (49 loc) · 2.23 KB
/
pups.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const puppeteer = require('puppeteer');
const fetch = require("node-fetch");
const axios = require('axios');
(async () => {
const browser = await puppeteer.launch({headless: false, defaultViewport: {
width: 1400,
height: 1400,
isMobile: false,
}}); // default is true
const page = await browser.newPage();
await page.setBypassCSP(true);
const res = await axios.get('http://localhost:8080/api/task')
.then(function (response) {
// handle success
console.log(response.data[0]);
return response.data
})
.catch(function (error) {
// handle error
console.log(error);
return error
})
.then(function (response) {
// handle success
return response
});
console.log(res[0].task)
await page.goto('https://facebook.com', {waitUntil: 'networkidle2'});
// await page.pdf({path: 'hn.pdf', format: 'A4'});
await page.type('input[name=email]', '<email>', {delay: 20})
await page.type('input[name=pass]', '<password>', {delay: 20})
await page.click('input[type=submit]', {waitUntil: 'networkidle2'}); // With type
await page.waitForNavigation({ waitUntil: 'networkidle0' }),
// await page.click('class=m9osqain a5q79mjw'); // With type
// await browser.waitForTarget(await page.$(".m9osqain .a5q79mjw"))
// let handles = await page.$('.m9osqain .a5q79mjw');
// await page.click(handles); // With type
await page.waitForSelector("#ssrb_root_start")
let element = await page.$('div.m9osqain.a5q79mjw')
// let value = await page.evaluate(el => el.textContent, element)
await page.click('div.m9osqain.a5q79mjw'); // With type
// await browser.waitUntil('div.notranslate', {visible: true})
await page.waitForSelector('div.oajrlxb2.tdjehn4e', {visible: true}),
await page.type('div.notranslate', ' ' + res[0]._id + '\n' + res[0].task + '\n' + res[0].status, {delay: 200})
//await page.evaluate((text) => { ( page.$('div.notranslate')).value = text; }, "Hello from Puppeteer Script");
await page.waitForSelector('div.oajrlxb2.s1i5eluu.qu0x051f', {visible: true}),
await page.click('div.oajrlxb2.s1i5eluu.qu0x051f'); // With type
await browser.close();
})();