admin管理员组文章数量:1023519
How in Playwright get in evaluate data from arguments? 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)
})
}
How in Playwright get in evaluate data from arguments? 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)
})
}
Share
Improve this question
asked Feb 3, 2022 at 11:18
rd100rd100
11 silver badge2 bronze badges
1
- Does this answer your question? Playwright pass variable into eval with JavaScript (Node) – ggorlen Commented Jul 18, 2022 at 15:09
1 Answer
Reset to default 4You have to pass to the evaluate
function a function that expects an argument. To avoid the confusion lets call it c
, and then you pass d
as a second argument to the evaluate
.
async function testEv(d) {
const data = await this.page.evaluate((c) {
console.log('d from args is', c)
}, d)
}
If you need to pass more than one argument you can pass an object
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,
})
}
How in Playwright get in evaluate data from arguments? 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)
})
}
How in Playwright get in evaluate data from arguments? 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)
})
}
Share
Improve this question
asked Feb 3, 2022 at 11:18
rd100rd100
11 silver badge2 bronze badges
1
- Does this answer your question? Playwright pass variable into eval with JavaScript (Node) – ggorlen Commented Jul 18, 2022 at 15:09
1 Answer
Reset to default 4You have to pass to the evaluate
function a function that expects an argument. To avoid the confusion lets call it c
, and then you pass d
as a second argument to the evaluate
.
async function testEv(d) {
const data = await this.page.evaluate((c) {
console.log('d from args is', c)
}, d)
}
If you need to pass more than one argument you can pass an object
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,
})
}
本文标签: javascriptHow in Playwright get in evaluate data from argumentsStack Overflow
版权声明:本文标题:javascript - How in Playwright get in evaluate data from arguments? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745545503a2155374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论