question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change to locator function breaks a lot of selectors

See original GitHub issue

The 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:open
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nitschSBcommented, Sep 2, 2019

It’s broken, when you use at, first or last in conjunction with find, withChild, withDescendant, inside, after or before.

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.

0reactions
miraocommented, Oct 17, 2019

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:

  • ver 2.2.1 as .//div[position()=2][@role = 'row'][contains(., 'Line 1')] which works
  • ver. 2.3.0 as (.//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")
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found