$eval can't find existing selector
See original GitHub issue- Puppeteer version: 1.3
- Platform / OS version: MacOS Sierra
- URLs (if applicable): https://archive.kbb1.com/lessons
- Node.js version: 9.0.8
I’m attempting to clear two input fields that contain dates range. Following code snippet clears first input field but fails to clear the second:
await page.$eval("div.five.wide.column > div.ui.grid > div:nth-child(2) > div:nth-child(1) > div > input[type=\"text\"]", (selector) => {
selector.value = "";
});
await page.$eval("div.five.wide.column > div.ui.grid > div:nth-child(2) > div:nth-child(2) > div > input[type=\"text\"]", (selector) => {
selector.value = "";
});
Steps to reproduce:
await page.goto('https://archive.kbb1.com/lessons', {waitUntil: 'networkidle2'});
// Clicking on Date filter
// Click Apply and check if filter tag is created
await Promise.all([
await page.click(".ui.blue.large.pointing.secondary.index-filters.menu div a:nth-child(4)"),
page.waitForSelector("div.five.wide.column > div.ui.grid > div:nth-child(2) > div:nth-child(2) > div > input")
]);
await page.$eval("div.five.wide.column > div.ui.grid > div:nth-child(2) > div:nth-child(1) > div > input[type=\"text\"]", (selector) => {
selector.value = "";
});
await page.$eval("div.five.wide.column > div.ui.grid > div:nth-child(2) > div:nth-child(2) > div > input[type=\"text\"]", (selector) => {
selector.value = "";
});
After executing following snippet, start date range field will be empty, but end date range field will still contain old date
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
page.$eval() not finding selector, selector works in console
I have tried using page.$eval(), page.evaluate() and page.evaluateHandle() using document.querySelector(). const url = await page ...
Read more >Page.$$eval() method - Puppeteer
This method runs Array.from(document.querySelectorAll(selector)) within the page and passes the result as the first argument to the pageFunction.
Read more >Puppeteer documentation - DevDocs
Puppeteer 7.1.0 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
Read more >Scraping & asserting on page elements - Checkly
Scrape the relevant item from the current page. ... eval() method which is a very powerful way to actually run a selector query...
Read more >ElementHandle class - puppeteer library - Dart API - Pub.dev
Resolves to true if the element is visible in the current viewport. ... $$eval<T>(String selector, String pageFunction, {List? args}) → Future<T?> This ...
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 FreeTop 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
Top GitHub Comments
I also encountered the same problem. use
page.evaluate
print errordocument is not defined
. But I usepage.evaluateHandle
fixed it.might be a good idea to use
page.waitForSelector
since the element only appear once there’s interaction within the page and then call the next command on that element to ensure it’s available when executing that code. Lately I’ve been appending a catch to all my awaits when debugging.await page.evaluate(document.querySelector('div.five.wide.column > div.ui.grid > div:nth-child(2) > div:nth-child(2) > div > input').value='').catch((e)=>{console.error(e)});
Hope this helps.