我正在使用Puppeteerpage.waitForFunction()方法:
await page.waitForFunction(`
(window.hero.x - 1 === ${x} || window.hero.x === ${x} || window.hero.x + 1 === ${x} || window.hero.x === ${x}) && (window.hero.y - 1 === ${y} || window.hero.y === ${y} || window.hero.y + 1 === ${y} || window.hero.y === ${y}) || window.hero.x === ${x} && window.hero.y === ${y}
`);
它正在工作,但看起来很糟糕。我想将其更改为多行。在文档中有:
page.waitForFunction(pageFunction[, options[, ...args]])
pageFunction<function|string>在浏览器上下文中要评估的功能
要将参数从node.js传递给page.waitForFunction函数谓词:
const selector = '.foo';
await page.waitForFunction(selector => !!document.querySelector(selector), {}, selector);
我这样尝试过:
console.log(x,y); // 24 42
await page.waitForFunction((x, y) => {
console.log(x, y); // undefined, undefined
if(x && y) {
return true;
}
});
但x和y这我试图通过是不确定的。我做错了什么?
千万里不及你
一只甜甜圈
相关分类