change to locator function breaks a lot of selectors
See original GitHub issueThe change of #1829 breaks a lot of selectors.
For example my universal td selector
locate('td') .withText(text) .at(columnNumber) .inside( this.tableRows(tableId) .withText(text) .at(_rowNumber) )
Puppeteer throws this exception: “Uncaught DOMException: Failed to execute … is not a valid XPath expression.” Reason: Brackets aren’t allowed in a “ancestor”-selector.
//*[ancestor::(//*)[1]]
By the way
removePrefix
does not work for those kind of selectors as well.
_Originally posted by @nitschSB in https://github.com/Codeception/CodeceptJS/pull/1829#issuecomment-523952794_
Since I don’t really understand what problem exactly this PR solves, I opened this ticket to discuss the change. At least to me it feels like it introduces more problem than it solves.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
The Ultimate Guide to Choosing Selectors for Automation
In this article we help you choose automation selectors and share pros ... Your locator should be universal so that if there are...
Read more >Writing Strong Front-end Test Element Locators
Front-end testing is awesome. We can write code, click on things like a user would, then make assertions. In this post, we'll go...
Read more >Error with composed selector · Issue #169 · reduxjs/reselect
I'm creating a composed selector with a simple selector from another file and I get this error. Uncaught Error: Selector creators expect all...
Read more >Locators In Selenium WebDriver With Examples
I have used the SelectorsHub tool to locate the desired WebElement using the ID locator. Below is the DOM structure of the element:....
Read more >Message: no such element: Unable to locate ...
Better to check for static text inside elements or something that is not gonna probably change in a short matter of time. If...
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
It’s broken, when you use
at
,first
orlast
in conjunction withfind
,withChild
,withDescendant
,inside
,after
orbefore
.The documentation of the Locator Builder API is a little sketchy.
locate('//tr/td').at(2);
may lead to//tr/td[position()=2]
or(//tr/td)[position()=2]
. I don’t know what to expect and what you want. I thing someone should decide quickly because it’s an API breaking change.I’ve just upgraded CodeceptJS to 2.3.x and I can see a regression.
The code
locate("div").at(2).withAttr({ role: "row" }).withText("Line 1")
is translated this way:.//div[position()=2][@role = 'row'][contains(., 'Line 1')]
which works(.//div)[position()=2][@role = 'row'][contains(., 'Line 1')]
which doesn’t work (tested in Chrome/Firefox)It works well only without
at(2)
As a workaround I had to adjust the locator a little bit. I replaced
at(2)
by one more attribute to narrow the locator:locate("div").withAttr({ "aria-rowindex": "2" }).withAttr({ role: "row" }).withText("Line 1")