From 1eb2aa7d42cc9df0127048ad09ddcdb94296c1ca Mon Sep 17 00:00:00 2001 From: Highwaist <162574330+Highwaist@users.noreply.github.com> Date: Wed, 12 Jun 2024 17:24:44 +0800 Subject: [PATCH] Update main_test.js --- lab4/main_test.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a5..942a2140 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -8,15 +8,20 @@ const puppeteer = require('puppeteer'); // Navigate the page to a URL await page.goto('https://pptr.dev/'); - // Hints: - // Click search button - // Type into search box - // Wait for search result - // Get the `Docs` result section - // Click on first result in `Docs` section - // Locate the title - // Print the title - - // Close the browser + await page.waitForSelector('.DocSearch-Button'); + await page.click('.DocSearch-Button'); + + await page.waitForSelector('.DocSearch-Form'); + await page.keyboard.type('chipi chipi chapa chapa'); + + await page.waitForSelector('#docsearch-item-5 a[href="/webdriver-bidi/#measuring-progress"]'); + await page.click('#docsearch-item-5 a[href="/webdriver-bidi/#measuring-progress"]'); + + await new Promise(resolve => setTimeout(resolve, 2000)); + + const fullTitle = await page.title(); + const desiredTitle = fullTitle.split(' | ')[0]; + console.log(desiredTitle); + await browser.close(); -})(); \ No newline at end of file +})();