Skip to content

Commit 38be1a9

Browse files
authored
Merge pull request #316 from 9ithu6-c0m/lab4
[LAB4] 313560001
2 parents fa5fec5 + 820639d commit 38be1a9

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

lab4/main_test.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
const puppeteer = require('puppeteer');
22

3+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
4+
35
(async () => {
4-
// Launch the browser and open a new blank page
56
const browser = await puppeteer.launch();
67
const page = await browser.newPage();
78

89
// Navigate the page to a URL
910
await page.goto('https://pptr.dev/');
1011

11-
// Hints:
1212
// Click search button
13-
// Type into search box
14-
// Wait for search result
15-
// Get the `Docs` result section
16-
// Click on first result in `Docs` section
17-
// Locate the title
18-
// Print the title
13+
await page.click("button.DocSearch");
14+
15+
await sleep(1000);
16+
17+
// Type chipi chipi chapa chapa in the search input
18+
await page.type("input.DocSearch-Input", "andy popoo");
19+
20+
await sleep(1000);
21+
22+
// click first element in the list
23+
await page.click("#docsearch-hits1-item-4 > a");
24+
25+
// log title
26+
const title = await page.evaluate(() => {
27+
return document.querySelector("div.theme-doc-markdown > header > h1").innerText;
28+
});
29+
console.log(title);
1930

2031
// Close the browser
2132
await browser.close();
22-
})();
33+
})();

0 commit comments

Comments
 (0)