How to execute javascript code with Playwright?

How can I execute "document.execCommand("insertText", false, "25810") from playwright?
5 Replies
flat-fuchsia
flat-fuchsiaOP•3y ago
this does now work page.evaluate("insertText", element);
flat-fuchsia
flat-fuchsiaOP•3y ago
unfortunately it does now work 🙂 is page.evaluate() the same as document.execCommand? can I somehow access document in playwright instead of page?
conscious-sapphire
conscious-sapphire•3y ago
Yes, inside page.evaluate.
const html = await page.evaluate(() => {
return document.documentElement.innerHTML
})
const html = await page.evaluate(() => {
return document.documentElement.innerHTML
})
flat-fuchsia
flat-fuchsiaOP•3y ago
thanks I found a solution now

Did you find this page helpful?