Skip to content

Commit ec2de93

Browse files
authored
Merge pull request #342 from SapphireLinXu/lab4
[LAB4] 312553027
2 parents 97331b3 + 1f7fdd2 commit ec2de93

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lab4/main_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,32 @@ const puppeteer = require('puppeteer');
1010

1111
// Hints:
1212
// Click search button
13+
await page.waitForSelector('#__docusaurus > nav > div.navbar__inner > div.navbar__items.navbar__items--right > div.navbarSearchContainer_IP3a > button > span.DocSearch-Button-Container > svg');
14+
await page.click('#__docusaurus > nav > div.navbar__inner > div.navbar__items.navbar__items--right > div.navbarSearchContainer_IP3a > button > span.DocSearch-Button-Container > svg');
1315
// Type into search box
16+
await page.waitForSelector('.DocSearch-Input');
17+
await page.type('.DocSearch-Input', 'andy popoo' , { delay: 100 });
18+
1419
// Wait for search result
20+
await page.waitForSelector('.DocSearch-Hit');
1521
// Get the `Docs` result section
1622
// Click on first result in `Docs` section
23+
await page.waitForSelector('.DocSearch-Hit', { timeout: 5000 });
24+
25+
const docsSection = await page.$$('.DocSearch-Hit');
26+
const limit = 5; // limit the number of results to show
27+
const visibleDocsSection = docsSection.slice(0, limit); // get the first 5 results
28+
29+
if (visibleDocsSection.length > 0) {
30+
await visibleDocsSection[4].click();
31+
} else {
32+
console.log('No results found');
33+
}
1734
// Locate the title
1835
// Print the title
36+
await page.waitForSelector('h1');
37+
const title = await page.$eval('h1', element => element.innerText);
38+
console.log(title);
1939

2040
// Close the browser
2141
await browser.close();

0 commit comments

Comments
 (0)