File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,32 @@ const puppeteer = require('puppeteer');
10
10
11
11
// Hints:
12
12
// Click search button
13
+ await page . waitForSelector ( '#__docusaurus > nav > div.navbar__inner > div.navbar__items.navbar__items--right > div.navbarSearchContainer_IP3a > button > span.DocSearch-Button-Container > svg' ) ;
14
+ await page . click ( '#__docusaurus > nav > div.navbar__inner > div.navbar__items.navbar__items--right > div.navbarSearchContainer_IP3a > button > span.DocSearch-Button-Container > svg' ) ;
13
15
// Type into search box
16
+ await page . waitForSelector ( '.DocSearch-Input' ) ;
17
+ await page . type ( '.DocSearch-Input' , 'andy popoo' , { delay : 100 } ) ;
18
+
14
19
// Wait for search result
20
+ await page . waitForSelector ( '.DocSearch-Hit' ) ;
15
21
// Get the `Docs` result section
16
22
// Click on first result in `Docs` section
23
+ await page . waitForSelector ( '.DocSearch-Hit' , { timeout : 5000 } ) ;
24
+
25
+ const docsSection = await page . $$ ( '.DocSearch-Hit' ) ;
26
+ const limit = 5 ; // limit the number of results to show
27
+ const visibleDocsSection = docsSection . slice ( 0 , limit ) ; // get the first 5 results
28
+
29
+ if ( visibleDocsSection . length > 0 ) {
30
+ await visibleDocsSection [ 4 ] . click ( ) ;
31
+ } else {
32
+ console . log ( 'No results found' ) ;
33
+ }
17
34
// Locate the title
18
35
// Print the title
36
+ await page . waitForSelector ( 'h1' ) ;
37
+ const title = await page . $eval ( 'h1' , element => element . innerText ) ;
38
+ console . log ( title ) ;
19
39
20
40
// Close the browser
21
41
await browser . close ( ) ;
You can’t perform that action at this time.
0 commit comments