Pass a function inside page.waitForFunction() with puppeteer(使用puppeteer在page.waitForFunction()内传递函数)
问题描述
以下是我的代码:
function hasDataBeenRefreshed(pastAvgGain, currentAvgGain) {
if (pastAvgGain!== currentAvgGain) {
return true
} else {
return false
}
}
async function getInfos(paire, page) {
let pastAvgGain = C.AVG_GAIN.textContent
await page.click(paire)
let currentAvgGain = C.AVG_GAIN.textContent
await page.waitForFunction(hasDataBeenRefreshed(pastAvgGain, currentAvgGain))
...
}
但是如果我这样做,我会收到此错误:
Error: Evaluation failed: TypeError: true is not a function
有没有办法达到这样的效果?
推荐答案
page.waitForFunction()接受回调,现在您传入的是一个布尔值。要解决此问题,您可以执行以下操作:
await page.waitForFunction((pastAvgGain, currentAvgGain) => {
if (pastAvgGain!== currentAvgGain) {
return true
} else {
return false
}
} , {} , pastAvgGain, currentAvgGain )
https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagewaitforfunctionpagefunction-options-args有关详细信息,请参阅文档
第三个参数是要传递给回调的参数
在您的评论之后:
await page.waitForFunction(() => {
return hasDataBeenRefreshed(pastAvgGain, currentAvgGain);
} )
这篇关于使用puppeteer在page.waitForFunction()内传递函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用puppeteer在page.waitForFunction()内传递函数
基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
