File tree Expand file tree Collapse file tree 1 file changed +25
-13
lines changed Expand file tree Collapse file tree 1 file changed +25
-13
lines changed Original file line number Diff line number Diff line change 1
1
const puppeteer = require ( 'puppeteer' ) ;
2
2
3
3
( async ( ) => {
4
- // Launch the browser and open a new blank page
5
4
const browser = await puppeteer . launch ( ) ;
6
5
const page = await browser . newPage ( ) ;
7
-
8
- // Navigate the page to a URL
9
6
await page . goto ( 'https://pptr.dev/' ) ;
10
7
11
- // Hints:
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
8
+ await page . setViewport ( { width : 1080 , height : 1024 } ) ;
9
+
10
+ await page . waitForSelector ( '.DocSearch-Button' ) ;
11
+ await page . click ( '.DocSearch-Button' ) ;
12
+
13
+ await page . waitForSelector ( '#docsearch-input' ) ;
14
+ await page . type ( '#docsearch-input' , "chipi chipi chapa chapa" )
15
+
16
+ await new Promise ( ( resolve ) => {
17
+ setTimeout ( ( resolve ) , 3000 )
18
+ } )
19
+
20
+ await page . waitForSelector ( '#docsearch-item-5 a' ) ;
21
+ await page . click ( '#docsearch-item-5 a' ) ;
22
+
23
+
24
+ await new Promise ( ( resolve ) => {
25
+ setTimeout ( ( resolve ) , 3000 )
26
+ } )
19
27
20
- // Close the browser
28
+ const element = await page . waitForSelector ( 'h1' ) ;
29
+ const title = await element . evaluate ( ( ele ) => {
30
+ return ele . textContent
31
+ } )
32
+ console . log ( title ) ;
21
33
await browser . close ( ) ;
22
- } ) ( ) ;
34
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments