File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change 1
1
const puppeteer = require ( 'puppeteer' ) ;
2
2
3
+ const sleep = ( ms ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
4
+
3
5
( async ( ) => {
4
- // 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
- // Type into search box
14
- // Wait for search result
15
- // Get the `Docs` result section
16
- // Click on first result in `Docs` section
17
- // Locate the title
18
- // Print the title
13
+ await page . click ( "button.DocSearch" ) ;
14
+
15
+ await sleep ( 1000 ) ;
16
+
17
+ // Type chipi chipi chapa chapa in the search input
18
+ await page . type ( "input.DocSearch-Input" , "andy popoo" ) ;
19
+
20
+ await sleep ( 1000 ) ;
21
+
22
+ // click first element in the list
23
+ await page . click ( "#docsearch-hits1-item-4 > a" ) ;
24
+
25
+ // log title
26
+ const title = await page . evaluate ( ( ) => {
27
+ return document . querySelector ( "div.theme-doc-markdown > header > h1" ) . innerText ;
28
+ } ) ;
29
+ console . log ( title ) ;
19
30
20
31
// Close the browser
21
32
await browser . close ( ) ;
22
- } ) ( ) ;
33
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments