From 1671390fb4b64bab9214fe50c550cfa92f03aa3d Mon Sep 17 00:00:00 2001 From: kalakala Date: Tue, 1 Apr 2025 11:56:41 +0800 Subject: [PATCH] complete lab4 --- lab4/main_test.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a..2541498 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -8,15 +8,24 @@ const puppeteer = require('puppeteer'); // Navigate the page to a URL await page.goto('https://pptr.dev/'); - // Hints: // Click search button + await page.waitForSelector('.DocSearch-Button'); + await page.click('.DocSearch-Button'); + // Type into search box + await page.locator('#docsearch-input').fill('andy popoo'); + // Wait for search result - // Get the `Docs` result section // Click on first result in `Docs` section + await page.locator('#docsearch-hits1-item-4 > a > div').click(); + // Locate the title - // Print the title + await page.waitForSelector('h1'); + const title = await page.$eval('h1', (element) => element.textContent); + // Print the title + console.log(title); + // Close the browser await browser.close(); })(); \ No newline at end of file