Skip to content

[LAB4] 313552017 #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lab4/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,26 @@ const puppeteer = require('puppeteer');

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

// set viewport size
await page.setViewport({ width: 1080, height: 1024 });
// Hints:
// Click search button
// 點擊搜尋按鈕
await page.click('.DocSearch-Button');
// 等待搜尋框出現
await page.waitForSelector('.DocSearch-Input');
await page.type('.DocSearch-Input', 'andy popoo');
// 等待搜尋結果出現
await page.waitForSelector("#docsearch-hits1-item-4 > a > div", { visible: true });
// 點擊搜尋結果
await page.click("#docsearch-hits1-item-4 > a > div");
// 等待新頁面載入並定位標題(例如 h1 標籤)
await page.waitForSelector('#__docusaurus_skipToContent_fallback > div > div > main > div > div > div > div > article > div.theme-doc-markdown.markdown > header > h1');

// 取得並印出標題文字
const title = await page.$eval('h1', el => el.textContent);
console.log(title);

// Type into search box
// Wait for search result
// Get the `Docs` result section
Expand Down