Skip to content

[LAB4] 313560001 #316

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 1 commit 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
29 changes: 20 additions & 9 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
const puppeteer = require('puppeteer');

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch();
const page = await browser.newPage();

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

// Hints:
// Click search button
// Type into search box
// Wait for search result
// Get the `Docs` result section
// Click on first result in `Docs` section
// Locate the title
// Print the title
await page.click("button.DocSearch");

await sleep(1000);

// Type chipi chipi chapa chapa in the search input
await page.type("input.DocSearch-Input", "andy popoo");

await sleep(1000);

// click first element in the list
await page.click("#docsearch-hits1-item-4 > a");

// log title
const title = await page.evaluate(() => {
return document.querySelector("div.theme-doc-markdown > header > h1").innerText;
});
console.log(title);

// Close the browser
await browser.close();
})();
})();
Loading