简体   繁体   English

点击 iframe 中的链接后的 Puppeteer 页面内容

[英]Puppeteer Page content after click on link in iframe

I load a page with iframe in it and click on a link in the iframe like this:我加载了一个包含 iframe 的页面,然后单击 iframe 中的链接,如下所示:

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.一切正常,puppeteer 导航到新页面。 Now I want to click on en element in the new page.现在我想在新页面中单击 en 元素。 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.给出了原始页面中iframe的原始内容。

How can I refer to the newly loaded page?如何参考新加载的页面?

I found the solution:)我找到了解决方案:)

The iframe link opened in a new tab. iframe 链接在新选项卡中打开。 Therefore I had to select it first like this:因此,我必须首先像这样 select 它:

const pages = await browser.pages()
const newPage = pages[pages.length - 1];
await newPage.bringToFront()
const content = await newPage.content();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM