Playwright 如何从参数中获取评估数据?page.evaluate: ReferenceError: d is not defined
async function testEv(d) {
const data = await this.page.evaluate(function() {
console.log('d from args is', d)
})
}
Playwright 如何从参数中获取评估数据?page.evaluate: ReferenceError: d is not defined
async function testEv(d) {
const data = await this.page.evaluate(function() {
console.log('d from args is', d)
})
}
您必须将一个需要参数的函数传递给evaluate
函数。为避免混淆,让我们调用它c
,然后将d
其作为第二个参数传递给evaluate
.
async function testEv(d) {
const data = await this.page.evaluate((c) {
console.log('d from args is', c)
}, d)
}
如果你需要传递多个参数,你可以传递一个对象
async function testEv(d) {
const data = await this.page.evaluate((obj) {
console.log('obj.foo from args is', obj.foo);
console.log('obj.bar from args is', obj.bar);
},
{
foo: d,
bar: d,
})
}