diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a..f98d35c 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -1,22 +1,33 @@ const puppeteer = require('puppeteer'); +const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + (async () => { - // Launch the browser and open a new blank page const browser = await puppeteer.launch(); const page = await browser.newPage(); // 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 + await page.click("button.DocSearch"); + + await sleep(1000); + + // Type chipi chipi chapa chapa in the search input + await page.type("input.DocSearch-Input", "andy popoo"); + + await sleep(1000); + + // click first element in the list + await page.click("#docsearch-hits1-item-4 > a"); + + // log title + const title = await page.evaluate(() => { + return document.querySelector("div.theme-doc-markdown > header > h1").innerText; + }); + console.log(title); // Close the browser await browser.close(); -})(); \ No newline at end of file +})();