Skip to content

Commit e19b9f5

Browse files
authored
Update main_test.js
1 parent 0078e0b commit e19b9f5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lab4/main_test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@ const puppeteer = require('puppeteer');
1010

1111
// Hints:
1212
// Click search button
13+
await page.click('button.DocSearch.DocSearch-Button'); //點擊指定按鈕
14+
1315
// Type into search box
1416
// Wait for search result
17+
await page.waitForSelector('#docsearch-input.DocSearch-Input'); //等待 id 為 docsearch-input 且具有 DocSearch-Input 類的元素出現在頁面上
18+
await page.type('#docsearch-input.DocSearch-Input', 'chipi chipi chapa chapa',{delay: 2000}); //將指定的文字 'chipi chipi chapa chapa' 輸入到 id 為 docsearch-input 且具有 DocSearch-Input 類的元素中
19+
1520
// Get the `Docs` result section
21+
await page.waitForSelector('#docsearch-item-5.DocSearch-Hit'); //等待 id 為 docsearch-item-5 且具有 DocSearch-Hit 類的元素出現在頁面上
1622
// Click on first result in `Docs` section
23+
await page.click('#docsearch-item-5.DocSearch-Hit'); //點擊指定按鈕
24+
1725
// Locate the title
26+
let titletext = await page.waitForSelector('#__docusaurus_skipToContent_fallback > div > div > main > div > div > div > div > article > div.theme-doc-markdown.markdown > h1'); //等待指定的元素出現在當前頁面上,並將內容存儲在變數 titletext 中
27+
let flag = await titletext.evaluate(element=> element.textContent); //使用 textContent 屬性來獲取指定文字內容
28+
1829
// Print the title
19-
30+
console.log(flag); //呈現指定內容
31+
2032
// Close the browser
2133
await browser.close();
22-
})();
34+
})();

0 commit comments

Comments
 (0)