简体   繁体   English

提交表单后,puppeteer新加载的页面

[英]puppeteer newly loaded page after the form submit

I am using puppeteer to measure the performance of the pages and their features (this is still in the initial phase, since I am just starting). 我正在使用puppeteer来衡量页面及其功能的性能(这仍处于初始阶段,因为我才刚刚开始)。 Here's an example I am using: 这是我正在使用的示例:

const puppeteer = require('puppeteer');
(async () => {

    const browser = await puppeteer.launch({headless: false});
    const page = await browser.newPage();
    await page._client.send('Performance.enable');
    await page.goto('https://xxxx.com');
    await page.focus("#formulario input#username");
    await page.type("test2222@gmail.com", {delay: 200});
    await page.focus("#formulario input#inputPassword3");
    await page.type("pass", {delay: 200});
    const loginForm = await page.$("#formulario");
    await loginForm.evaluate(loginForm => loginForm.submit());
    loginForm._client.send('Performance.getMetrics');
    //BELOW DOESN'T WORK BECAUSE THE PAGE IS GONE
    await page.click("span.show-filters");

    await browser.close();
})();

How to access the newly loaded page after a form is submitted? 提交表单后如何访问新加载的页面? I mean the user has logged in and how can we get a handle of that newly loaded page? 我的意思是用户已登录,我们如何获得该新加载页面的句柄?

I've got it working by waiting for the page to load first. 我通过等待页面首先加载来使其工作。 Then I was able to click the correct element. 然后,我能够单击正确的元素。

So I've added the following line: 因此,我添加了以下行:

await page.waitForNavigation();

before this one: 在此之前:

await page.click(".show-filters");

I must say that the documentation is rather scarce for the tool :( 我必须说,该工具的文档非常少:(

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

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