Messing around with puppeteer, and not seeing this question answered anywhere, although it has been asked a few times:
Expected result: 1. Click on tag via its class name 2. wait for new page (linked in tag) to finish loading 3. take a screenshot of new page to demonstrate this process has been successful
Here's my code:
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.setViewport({
width: 800,
height: 600
})
await page.goto('https://www.example.com/')
await page.click('.targeted_class_with_a_tag')
await page.waitForNavigation({ waitUntil: 'networkidle2' })
await page.screenshot({
path: 'mouse_click.png'
})
await browser.close()
I expected the screenshot to contain the page navigated to via the clicked tag. Instead it times out. If I remove the waitForNavigation, it just screenshots the initial page loaded.
Can anyone tell me where I have gone wrong here?
Thanks!