-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #598 from as10968574/lab4
[LAB4] 510558017
- Loading branch information
Showing
1 changed file
with
20 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})(); | ||
})(); |