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.

CollectionContition could accept `List<SelenideElement>` instead of `List<WebElement>`

See original GitHub issue

The problem

It would be more convenient to use Predicate<SelenideElement> instead of Predicate<WebElement> in methods allMatch, anyMatch, noneMatch.

Details

Now folks need to implement allMatch like this:

trs.shouldBe(allMatch("all value same in column",
                    e -> e.findElements(By.tagName("td")).get(i).getText().equals(cellValue)));

it would be simpler if allMatch accepted Predicate<SelenideElement>:

trs.shouldBe(allMatch("all value same in column",
                    e -> e.findAll("td").get(i).has(text(cellValue));

Pros

The following things would be possible (which are not possible now):

  • Navigation: search for inner elements using e.find("[class*='<class-part>']")
  • Use execute methods from SelenideElement.
  • Use pseudo-elements
  • Use Conditions and other SelenideElement methods.

Note that current approach forces users to mix Selenium and Selenide syntax which is probably bad.

Cons:

I see a potential risk if folks use “waiting” methods of SelenideElement like shouldHave.
The point of $$.allMatch and other collection checks is that they can wait (if condition is not satisifed yet). If we give access to SelenideElement inside allMatch (and other CollectionCondition), folks can call methods like .shouldHave(…), and then we get “waiting inside waiting”. It may become an untrackable nightmare.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
asolntsevcommented, Aug 4, 2020

@sergiomartins8 Ok, I understand. I started thinking that probably we could add to Selenide this feature: When you execute command $$("#books .book:visible").shouldHave(size(1)), Selenide loads only the number of elements using JavaScript without fetching the whole WebElement instances from WebDriver. It would be a great optimisation.

I even think that all those checks like $$("#books .book:visible").shouldHave(texts("foo", "bar", "zoo")) could be done via JavaScript which would make them much more efficient.

I registered a separate issue for this idea: https://github.com/selenide/selenide/issues/1244.

0reactions
asolntsevcommented, Dec 26, 2020

Closing this feature request in favor of #1244.

I realized that it’s ok for Condition and CollectionCondition implementations to use Selenium API, not Selenide API. They are low-level “bricks” for Selenide, and typical users don’t need to implement them in most cases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class ElementsCollection - Selenide
Instead, try to write a CollectionCondition which verifies the whole collection. Specified by: listIterator in interface List<SelenideElement>; Overrides: ...
Read more >
ElementsCollection · Selenide User Guide
This object can be created by calling the $$ method and represents the list of web-elements on the page. The following types of...
Read more >
How to use List <> with WebElement in selenide?
I would like to replace it with List . The code in selenide looks like this: ElementsCollection trElements = $$ ("tr");.
Read more >
Index (selenide 3.5.1 API) - javadoc.io
Append given test to the text field and trigger "change" event. apply(List<WebElement>) - Method in class com.codeborne.selenide.collections.ExactTexts ...
Read more >
How to print text from a list of all web elements with same ...
Thanks, its working... can you please explain the below for loop condition. for (WebElement webElement : bakeries). commented Mar 30, 2020 ...
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