Apify Discord Mirror

Updated 5 months ago

How to execute javascript code with Playwright?

At a glance

The community members are discussing how to execute the JavaScript command document.execCommand("insertText", false, "25810") using Playwright. Some community members suggest using page.evaluate() as an alternative, but it does not seem to work. Another community member mentions using page.waitForFunction() and accessing the document object within page.evaluate(). The community members are trying to find a solution, but there is no explicitly marked answer.

Useful resources
How can I execute "document.execCommand("insertText", false, "25810") from playwright?
C
A
L
7 comments
this does now work
page.evaluate("insertText", element);
unfortunately it does now work πŸ™‚
is page.evaluate() the same as document.execCommand?
can I somehow access document in playwright instead of page?
Yes, inside page.evaluate.

Plain Text
const html = await page.evaluate(() => {
   return document.documentElement.innerHTML
})
thanks I found a solution now
Add a reply
Sign up and join the conversation on Discord