【发布时间】:2017-11-27 14:52:01
【问题描述】:
我目前正在使用 Puppeteer,每当我调用此函数时,“选择器”都是未定义的。
async function verifyTextPresent(page, selector){
let myButton = await page.evaluate(() => document.querySelector(selector).innerText);
console.log(myButton);
}
错误:
(node:6996) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Evaluation failed: ReferenceError: selector is not defined
at <anonymous>:1:20
(node:6996) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the
Node.js process with a non-zero exit code.
【问题讨论】:
-
这是在页面准备好之前调用的吗?
-
是否必须将
document传递给evaluate函数?page.evaluate(document => document.querySelector(selector).innerText)。 (另外,可能值得使用textContent而不是innerText)。
标签: javascript jquery parameter-passing puppeteer