Skip to content

ElementQuery#get not working with conditions #2033

@probert94

Description

@probert94

I have an ElementQuery with a condition like withPropertyValue(elem -> elem.getProperty("test"), "value").
When this condition is not met on the first element the query would return without the condition, I get a NoSuchElementException event when executing first or get(0). When I call all().get(0) instead, I get the expected result.

Looking at the code in ElementQuery this does make sense:
In ElementQuery#executeSearch (L1357-1359) the index is used in javascript to extract the result at index.
The conitions are evaluated after that and only get the extracted entry.

The method last is not affected by this issue as it uses all to get all matches as a list and then extracts the last element from there.
Unfortunately this version is affected by another issue I created a few years ago.

Steps to reproduce:
MainView.java

public MainView() {
  var btn1 = new Button();
  var btn2 = new Button();
  btn2.getElement().setProperty("test", "XYZ");
  add(btn1, btn2);
}

MainViewIT.java

@BrowserTest
public void testButtonWithProperty() {
  Assertions.assertNotNull($(ButtonElement.class)
    .withPropertyValue(elem -> elem.getProperty("test"), "XYZ")
    .all()
    .get(0)
  );
  $(ButtonElement.class)
    .withPropertyValue(elem -> elem.getProperty("test"), "XYZ")
    .first();
}

Note that the Assertion passes, while the call to first does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    🔎Iteration reviews

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions