Skip to content

Commit 2384b7d

Browse files
committed
restore package
1 parent f320d0e commit 2384b7d

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

lab4/main_test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,46 @@ 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.type('.navbarSearchContainer_IP3a input', 'chipi chipi chapa chapa');
17+
await page.waitForSelector('.DocSearch-Input');
18+
await page.type('.DocSearch-Input', 'andy popoo' , { delay: 100 });
19+
1420
// Wait for search result
21+
await page.waitForSelector('.DocSearch-Hit');
1522
// Get the `Docs` result section
1623
// Click on first result in `Docs` section
24+
await page.waitForSelector('.DocSearch-Hit', { timeout: 5000 });
25+
26+
const docsSection = await page.$$('.DocSearch-Hit');
27+
const limit = 5; // limit the number of results to show
28+
const visibleDocsSection = docsSection.slice(0, limit); // get the first 5 results
29+
if (visibleDocsSection.length > 0) {
30+
for (let i = 0; i < visibleDocsSection.length; i++) {
31+
const title = await visibleDocsSection[i].$eval('.DocSearch-Hit-title', el => el.innerText);
32+
// console.log(`搜尋結果 ${i + 1}: ${title}`);
33+
}
34+
35+
// Click the first result
36+
const clickedTitle = await visibleDocsSection[0].$eval('.DocSearch-Hit-title', el => el.innerText);
37+
// console.log(`即將點擊的搜尋結果: ${clickedTitle}`);
38+
39+
await visibleDocsSection[4].click();
40+
} else {
41+
console.log('Results not found!');
42+
}
43+
// if (visibleDocsSection.length > 0) {
44+
// await visibleDocsSection[0].click(); // 點擊第一個搜尋結果
45+
// } else {
46+
// console.log('搜尋結果沒有找到!');
47+
// }
1748
// Locate the title
1849
// Print the title
19-
50+
await page.waitForSelector('h1');
51+
const title = await page.$eval('h1', element => element.innerText);
52+
console.log(title);
2053
// Close the browser
2154
await browser.close();
2255
})();

0 commit comments

Comments
 (0)