【发布时间】:2018-03-14 17:24:54
【问题描述】:
在 puppeteer 中切换标签时出错:
await page2.waitForSelector('#save');
await page2.click('#save'); //for saving and closing the page
await page2.waitFor(4000); // !!it will crash if I remove this line!!
const allPages = await browser.pages();
const page1 = await allPages[0];
await page1.waitFor(5000);// change nothing even if I wait 10 seconds
await page1.waitForSelector("selector")//crash if I delete 3rd line
当我在没有第 3 行的情况下运行此代码时,它会触发错误:
错误:错误:协议错误(Runtime.evaluate):会话关闭。 该页面很可能已关闭。 在 CDPSession.send(c:\path\node_modules\puppeteer\lib\Connection.js:172:29) 在 ExecutionContext.evaluateHandle (c:\path\node_modules\puppeteer\lib\ExecutionContext.js:56:77) 在 EventEmitter._document._documentPromise._contextPromise.then (c:\path\node_modules\puppeteer\lib\FrameManager.js:310:38)
而page2.waitForNavigation 对我不起作用,它会冻结页面。
我想知道如果我不使用该功能为什么它会崩溃:page2 上的 waitFor(4000) 以及是否有一种方法可以自动等待不浪费时间
或者我应该在点击按钮后等待 page2 完全关闭?
【问题讨论】:
标签: javascript automated-tests google-chrome-devtools integration-testing puppeteer