-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathmain_test.js
More file actions
37 lines (29 loc) · 1.16 KB
/
main_test.js
File metadata and controls
37 lines (29 loc) · 1.16 KB
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
const puppeteer = require('puppeteer');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Navigate the page to a URL
await page.goto('https://pptr.dev/');
// Hints:
// Click search button
await page.waitForSelector('button.DocSearch-Button', { visible: true });
await page.click('button.DocSearch-Button');
// Type into search box
await page.waitForSelector('#docsearch-input');
await page.type('#docsearch-input', 'andy popoo');
await sleep(300);
// Wait for search results
await page.waitForSelector('#docsearch-hits1-item-4 > a > div', { visible: true });
await page.click('#docsearch-hits1-item-4 > a > div');
// Find the first result in the Docs section and click it
await page.waitForSelector('h1');
const title = await page.$eval('h1', el => el.textContent.trim());
// Wait for navigation to finish and the title to appear
console.log(title)
// Close the browser
await browser.close();
})();