I load a page with iframe in it and click on a link in the iframe like this:
const elementHandle = await page.$('iframe');
const frame = await elementHandle.contentFrame();
await frame.click('a');
await page.waitFor(5000);
Everything works fine, puppeteer navigates to the new page. Now I want to click on en element in the new page. But I don't find the content of the new page.
const content = await page.content();
Gives the original page.
const content = await frame.content();
Gives the original content of the iframe in the original page.
How can I refer to the newly loaded page?
I found the solution:)
The iframe link opened in a new tab. Therefore I had to select it first like this:
const pages = await browser.pages()
const newPage = pages[pages.length - 1];
await newPage.bringToFront()
const content = await newPage.content();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.