A&C
Apify & Crawlee
C
Apify & Crawlee
•
4y ago
Casper
How to execute javascript code with Playwright?
How can I execute
"document
.execCommand
(
"insertText
"
, false
,
"25810
"
) from playwright
?
Apify & Crawlee
Join
This is the official developer community of Apify and Crawlee.
13,249
Members
View on Discord
Was this page helpful?
Yes
No
C
Casper
OP
•
9/26/22, 10:54 PM
this does now work
page
.evaluate
(
"insertText
"
, element
)
;
A
Alexey Udovydchenko
•
9/26/22, 11:07 PM
as alternative
https://playwright.dev/docs/api/class-page#page-wait-for-function
and if you need json output
https://playwright.dev/docs/api/class-jshandle#js-handle-json-value
C
Casper
OP
•
9/27/22, 12:48 PM
unfortunately it does now work
C
Casper
OP
•
9/27/22, 12:49 PM
is page
.evaluate
(
) the same as document
.execCommand
?
C
Casper
OP
•
9/27/22, 12:56 PM
can I somehow access document in playwright instead of page
?
L
Lukas Krivka
•
9/27/22, 1:26 PM
Yes
, inside page
.evaluate
.
const html = await page.evaluate(() => { return document.documentElement.innerHTML })
const html = await page.evaluate(() => { return document.documentElement.innerHTML })
C
Casper
OP
•
9/28/22, 4:58 PM
thanks I found a solution now
const
html
=
await
page.
evaluate
(()
=>
{
return
document.documentElement.innerHTML
})
const
html
=
await
page.
evaluate
(()
=>
{
return
document.documentElement.innerHTML
})