Skip to content

Commit a3de2f5

Browse files
authored
Merge pull request #598 from as10968574/lab4
[LAB4] 510558017
2 parents 5d39153 + 7b741df commit a3de2f5

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

lab4/main_test.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
const puppeteer = require('puppeteer');
22

33
(async () => {
4+
45
// 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+
await page.click('button.DocSearch.DocSearch-Button');
14+
1315
// Type into search box
14-
// Wait for search result
15-
// Get the `Docs` result section
16-
// Click on first result in `Docs` section
16+
await page.waitForSelector('#docsearch-input');
17+
await page.type('#docsearch-input', 'Experimental WebDriver BiDi support', { delay: 150 });
18+
19+
// Wait for search result and click on the first result
20+
await page.waitForSelector('.DocSearch-Hits', { timeout: 60000 });
21+
const hits = await page.$$('.DocSearch-Hit');
22+
if (hits.length > 0) {
23+
await hits[0].click();
24+
} else {
25+
throw new Error('No search results found');
26+
}
27+
1728
// Locate the title
29+
let textSelector = await page.waitForSelector('h1', { timeout: 60000 });
30+
let title = await textSelector.evaluate(element => element.textContent);
31+
1832
// Print the title
33+
console.log(title);
1934

2035
// Close the browser
2136
await browser.close();
22-
})();
37+
})();

0 commit comments

Comments
 (0)