From 3f7246d5099953c75b59309e648bd21b68db9aab Mon Sep 17 00:00:00 2001 From: show0609 Date: Tue, 1 Apr 2025 02:03:11 +0800 Subject: [PATCH] lab4: update main_test.js --- lab4/main_test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a..ee96f0c 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -10,12 +10,27 @@ const puppeteer = require('puppeteer'); // Hints: // Click search button + await new Promise(resolve => setTimeout(resolve, 3000)); + await page.locator('.DocSearch-Button-Placeholder').click(); + // Type into search box + await page.waitForSelector('.DocSearch-Input'); + await page.type('.DocSearch-Input','andy popoo'); + // Wait for search result // Get the `Docs` result section // Click on first result in `Docs` section + await new Promise(resolve => setTimeout(resolve, 3000)); + const element = await page.waitForSelector('#docsearch-hits1-item-4'); + await element.click(); + // Locate the title + await new Promise(resolve => setTimeout(resolve, 3000)); + const textSelector = await page.waitForSelector('header h1'); + // Print the title + const fullTitle = await textSelector?.evaluate(el => el.textContent); + console.log(fullTitle); // Close the browser await browser.close();