[Feature] Auto-wait in page.$eval?
See original GitHub issueWhile debugging @mynar7’s issue on slack, I noticed that the page.waitForNavigation
was not a reliable way to ensure that the #catalog-title
is visible. Replacing it with a page.waitForSelector
fixed it.
However, since we are moving towards auto-waits in API calls that refer to element selectors, I was wondering if the page.$eval
method could auto-wait for the element, thereby eliminating the need to waitForSelector
.
const { firefox, chromium, webkit } = require('playwright');
const assert = require('assert');
(async() => {
const browser = await firefox.launch();
const page = await browser.newPage();
await page.goto('https://realtruck.com/?disableIntegration=all');
await Promise.all([
page.click('text=Tonneau Covers'),
page.waitForSelector('#catalog-title') // was earlier using page.waitForNavigation()
]);
const header = await page.$eval('#catalog-title', el => el.textContent);
assert(header, "Tonneau Covers");
await browser.close();
})();
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Page.$eval() method - Puppeteer
Page.$eval() method. This method runs document.querySelector within the page and passes the result as the first argument to the pageFunction .
Read more >How to wait for JavaScript to finish in playwright - Stack Overflow
I think you can use setTimeout with page.evaluate inside the page context to wait a bit for other JavaScript to run: await page.evaluate(() ......
Read more >Timeouts | Checkly
Playwright click and fill methods will auto-wait for the element to be visible. ... 5000 }) const links = await page.evaluate(() => Array.from(document....
Read more >playwright._impl._api_types.error: execution context was ...
I am just using got function but it gives me the error. ... page.evaluate: Execution context was destroyed, most likely because of a...
Read more >Core concepts | Playwright 中文文档
Actions like click and fill auto-wait for the element to be visible and ... The page.evaluate API can run a JavaScript function in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We keep thinking in this direction, but there are a few concerns particularly regarding
page.$eval
:waitForSelector
has some interesting options and might get more in future; and there’s no good shape forpage.$eval
to accept these options.waitFor..
- it self-explains the API for non-experienced users.So we’ll keep thinking about this! For now, I think I can re-write your snippet in a slightly nicer way:
@thernstig yes, it does not wait for selector to appear. The semantic is the same as the
$
in devtools console, or in jquery - they just fetch element from the page.If you want to wait for a selector, you should use
page.waitfor("foo")