In a Playwright test what is the recommended method to execute JavaScript that is already loaded in the page (such as a global library, or page specific function)?
So if my page has JavaScript in it that creates a function named pageFunction
on load. How do I then call/trigger that function from a Playwright test?
I tried page.evaluate
but that returns an undefined method error. It's unable to find the pageFunction
at all.
Thanks for your help.
This thread is trying to answer question "How can I execute JavaScript that is already loaded in a page using Playwright?"
You have to attach it to window to be able to call it in Playwright, the scope you are talking is « lost ». Attach it to window and it should solve your problem.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].