【问题标题】:page.waitForFunction not recognizing page function argumentspage.waitForFunction 无法识别页面函数参数
【发布时间】:2021-12-28 17:43:50
【问题描述】:

我写了以下函数

async function getMatches(page, eventCount) {
    
    await page.waitForFunction((eventCount) => {
            let newCount = document.querySelectorAll('ms-event.grid-event').length
            console.log(eventCount) // this logs as '#document' on the chromium console!
            if (eventCount != newCount) {
                return true
            } else {
                return false
            }
    }, {}, eventCount)
}

// function call
await getMatches(page, 0)

其中 evenCount 是一个数字。这应该等待新的网格元素加载并仅在加载时才解析(newCount 将不同于作为输入传递的 eventCount)。

但是,该函数甚至不将 eventCount 识别为输入并将其记录为整个 html 文档(在 chromium 控制台内)。

这使函数立即解析,而不是等待新元素加载。

关于为什么会发生这种情况的任何线索?

【问题讨论】:

  • 你能分享一个minimal reproducible example,显示你定义eventCount的位置吗?
  • 我在原帖中编辑了代码,希望现在更清楚了。请注意,无论是通过 eventCount 变量还是直接传递实际数字,我都会遇到相同的#document 问题
  • 我看不出这不应该起作用的原因,所以它仍然无法重现。您提到in an answer 在重新安装之前和之后运行的 Puppeteer 版本是什么?

标签: javascript puppeteer


【解决方案1】:

我重新安装了 puppeteer,现在它可以正常工作了

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2015-04-15
  • 1970-01-01
  • 1970-01-01
  • 2019-07-14
  • 2013-08-09
  • 2015-02-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多