XPATH contains not working with page.$x
See original GitHub issueI am using latest puppeteer version and trying to click on span
element with text, but returns undefined
.
const setting = await page.$x('//span[contains(text(), "Settings")]'); // setting is undefined and setting.click() don't work
However, I can get all span
element with following
const setting = await page.$x('//span'); // returns array of span elements
I am still trying to iterate over span elements to find exact span with correct textContent but still i get is undefined.
const setting = spans.filter(span => span.textContent === 'Settings');
// still undefined.
Is there any easy way to find/click element with text content Same things perfectly works on selenium. Is this issue in puppeteer ?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
XPath contains(text(),'some string') doesn't work when used ...
The following query returns the element, but it returns far more then just the element – it returns the parent elements as well,...
Read more >How does XPath contains works? - eduCBA
Xpath Contains is an XPath function that is used to find Dynamic web elements and returns a partial attribute value to locate the...
Read more >XPath Contains: Text, Following Sibling & Ancestor in Selenium
XPath contains is a function within Xpath expression which is used to search for the web elements that contain a particular text. We...
Read more >Puppeteer - Xpath Functions - Tutorialspoint
The xpath for the element shall be //*[text()='Library']. Here, we are working with the xpath selector, so we have to use the method:...
Read more >XPath Contains Text | XPath Starts With, Ends With
XPath axes in selenium are methods to identify those dynamic elements which are not possible to find by normal XPath method such as...
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 think it is always better to
waitFor
element to be visible in DOM before trying to click/accessing it.@shankarregmi My bad I was trying to click on the settings before it was completely loaded into DOM, your solution perfectly works for me. Thanks.