Skip to content

Commit

Permalink
Merge pull request #598 from as10968574/lab4
Browse files Browse the repository at this point in the history
[LAB4] 510558017
  • Loading branch information
TaiYou-TW authored Jun 26, 2024
2 parents 5d39153 + 7b741df commit a3de2f5
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
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
await page.click('button.DocSearch.DocSearch-Button');

// Type into search box
// Wait for search result
// Get the `Docs` result section
// Click on first result in `Docs` section
await page.waitForSelector('#docsearch-input');
await page.type('#docsearch-input', 'Experimental WebDriver BiDi support', { delay: 150 });

// Wait for search result and click on the first result
await page.waitForSelector('.DocSearch-Hits', { timeout: 60000 });
const hits = await page.$$('.DocSearch-Hit');
if (hits.length > 0) {
await hits[0].click();
} else {
throw new Error('No search results found');
}

// Locate the title
let textSelector = await page.waitForSelector('h1', { timeout: 60000 });
let title = await textSelector.evaluate(element => element.textContent);

// Print the title
console.log(title);

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

0 comments on commit a3de2f5

Please sign in to comment.