[英]puppeteer newly loaded page after the form submit
我正在使用puppeteer來衡量頁面及其功能的性能(這仍處於初始階段,因為我才剛剛開始)。 這是我正在使用的示例:
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();
})();
提交表單后如何訪問新加載的頁面? 我的意思是用戶已登錄,我們如何獲得該新加載頁面的句柄?
我通過等待頁面首先加載來使其工作。 然后,我能夠單擊正確的元素。
因此,我添加了以下行:
await page.waitForNavigation();
在此之前:
await page.click(".show-filters");
我必須說,該工具的文檔非常少:(
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.