Skip to content
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

[LAB4] 312552020 #374

Merged
merged 19 commits into from
Apr 9, 2024
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
25 changes: 18 additions & 7 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ const puppeteer = require('puppeteer');
// 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
const searchButtonSelector = 'button[class="DocSearch DocSearch-Button"]';
await page.waitForSelector(searchButtonSelector);
await page.click(searchButtonSelector);

// Type into search box & Wait for search result
const searchInputSelector = 'input[class="DocSearch-Input"]';
await page.waitForSelector(searchInputSelector);
await page.type(searchInputSelector, 'chipi chipi chapa chapa', {delay: 200});

// Wait for search result, then Click on the first result in `Docs` section
const hitSelector = 'li[id="docsearch-item-5"]';
await page.waitForSelector(hitSelector);
await page.click(hitSelector);

// Locate & Print the title
const titleSelector = await page.waitForSelector('h1');
const fullTitle = await titleSelector?.evaluate(el => el.textContent);
console.log(fullTitle);

// Close the browser
await browser.close();
Expand Down
Loading