0

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)
  })
}
1

1 Answer 1

4

You 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,
  })
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.