Skip to content

[LAB4] B132016 #311

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

Open
wants to merge 1 commit into
base: b132016
Choose a base branch
from
Open
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
49 changes: 30 additions & 19 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
const puppeteer = require('puppeteer');

(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

// Close the browser
await browser.close();
})();
const browser = await puppeteer.launch();
const page = await browser.newPage();

await page.goto('https://pptr.dev/');
await page.setViewport({ width: 1080, height: 1024 });

await page.click('button.DocSearch.DocSearch-Button');
await page.waitForSelector('input#docsearch-input.DocSearch-Input');

await page.type('input#docsearch-input.DocSearch-Input', 'andy popoo');

await page.waitForSelector('.DocSearch-Hit');

const links = await page.$$('.DocSearch-Hit a');

for (const link of links) {
const text = await link.evaluate(el => el.textContent.trim());
if (text === 'ElementHandle.dragAndDrop() method') {
const href = await link.evaluate(el => el.href);
await page.goto(href);
break;
}
}

const titleElement = await page.waitForSelector('h1');
const fullTitle = await titleElement.evaluate(el => el.textContent.trim());
console.log(fullTitle);

await browser.close();
})();
Loading