File tree 1 file changed +20
-5
lines changed
1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change 1
1
const puppeteer = require ( 'puppeteer' ) ;
2
2
3
3
( async ( ) => {
4
+
4
5
// Launch the browser and open a new blank page
5
6
const browser = await puppeteer . launch ( ) ;
6
7
const page = await browser . newPage ( ) ;
7
8
8
9
// Navigate the page to a URL
9
10
await page . goto ( 'https://pptr.dev/' ) ;
10
11
11
- // Hints:
12
12
// Click search button
13
+ await page . click ( 'button.DocSearch.DocSearch-Button' ) ;
14
+
13
15
// Type into search box
14
- // Wait for search result
15
- // Get the `Docs` result section
16
- // Click on first result in `Docs` section
16
+ await page . waitForSelector ( '#docsearch-input' ) ;
17
+ await page . type ( '#docsearch-input' , 'Experimental WebDriver BiDi support' , { delay : 150 } ) ;
18
+
19
+ // Wait for search result and click on the first result
20
+ await page . waitForSelector ( '.DocSearch-Hits' , { timeout : 60000 } ) ;
21
+ const hits = await page . $$ ( '.DocSearch-Hit' ) ;
22
+ if ( hits . length > 0 ) {
23
+ await hits [ 0 ] . click ( ) ;
24
+ } else {
25
+ throw new Error ( 'No search results found' ) ;
26
+ }
27
+
17
28
// Locate the title
29
+ let textSelector = await page . waitForSelector ( 'h1' , { timeout : 60000 } ) ;
30
+ let title = await textSelector . evaluate ( element => element . textContent ) ;
31
+
18
32
// Print the title
33
+ console . log ( title ) ;
19
34
20
35
// Close the browser
21
36
await browser . close ( ) ;
22
- } ) ( ) ;
37
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments