2

I'm using Selenide and looking for an opportunity to create children ElementsCollection based on a parent's one. For example, I have a web table and a parent ElementsCollection consisting of table rows. So, after filtering this collection by some condition, I get, for example, 50 result rows. Then need to save the first cell in each row as a SelenideElement in a new ElementsCollection (children). This case doesn't have any issues, if I use List, because I can do this using stream() as:

List<SelenideElement> parents = $$("parent_css_selector");
List<SelenideElement> children = parents.stream().filter(s -> s.getText().equals("some_text")).map(s -> s.$("child_css_locator")).collect(Collectors.toList());

//or even in List<String> if I need to...

List<String> childrenTexts = parents.stream().filter(s -> s.getText().equals("some_text")).map(s -> s.$("child_css_locator")).getText().collect(Collectors.toList());

But since stream() was deprecated in Selenide 6.2.0 I cant find an opportunity to do this.

balantain
  • 105
  • 2
  • 8

2 Answers2

1

I've raised this question in specialized Selenide topics in Gitter and GitHub. And I would like to note that I received a response within an hour and it is very valuable approach in project development and support. )) Here is the answer of Andrei Solntsev, Selenide founder.

I recommend to avoid such long iterations etc. It causes slow tests. Instead, I would write a proper xpath that finds all the needed elements with just one web driver call.

I registered a feature request for adding non-deprecated stream() method: #1773

I really DON’T RECOMMEND using iterating elements this way. Such a test is highly ineffective. Just write a CollectionCondition as the deprecation notice recommends.

As far as I understood, he will return non-deprecated stream() in ElementsCollection.

balantain
  • 105
  • 2
  • 8
0

Your IDE should sort this out for you. Since stream() is deprecated you can replace it with a for loop, such as this

List<SelenideElement> children;
    
{
  List<SelenideElement> list = new ArrayList<>();
  for (SelenideElement s : parents) {
    if (s.getText().equals("some_text")) {
      SelenideElement child_css_locator = s.$("child_css_locator");
      list.add(child_css_locator);
    }
  }
  children = list;
}

IntelliJ generated this automatically, apologies if it's not exactly what you wanted but it no longer relies on stream().

Iainn
  • 66
  • 6
  • Thanks a lot! It’s also the way of solving this issue. But, I expected, that there is a way to do with Selenide itself. Nevertheless, I’ve already raised this question in Selenide topic in Gitter. They have assured me, that they would return back an opportunity to run stream from ElementsCollection in next release. – balantain Apr 21 '22 at 13:15