1.报错信息

(node:13852) UnhandledPromiseRejectionWarning: TimeoutError: Navigation Timeout
Exceeded: 30000ms exceeded

2.解决方法

const timeout = 180 * 1000
await Promise.all([
  page.goto('http://website.com', {timeout}),
  page.waitFor('body', {timeout})
])

或者

await page.goto('http://website.com', {timeout: 180000})

by default each time a page navigate to an url (page.goto) it waits for the event ‘load’ to be fired and by default it waits 30000ms, if the event (load) is not fired the page throw: Timeout Exceeded

probably you are loading a heavy or slow page you should change timeout to a bigger value depending on how much time your page take to load you can do that

timeout参数是load事件触发前允许等待的时间,并不会真的等待这么久后再执行下一步,因此在单页应用中timeout并不能保证页面渲染完成,此时需要使到page.waitForSelector确保相关的dom渲染成功

3.其它-选择器

page.click('#the-list tr:nth-child(2) .row-title');  // 点击列表下第二个元素的标题

相关::first-child :last-child

参考链接:https://github.com/GoogleChrome/puppeteer/issues/4275
https://developer.mozilla.org/zh-CN/docs/Web/API/Document/querySelector

作者 铁血 汉子 2019年6月18日
2024/12/22/01:37:51am 2019/6/18/8:59:26
0 4035