创建基于父母的elementsCollection在Selenide中的一个

发布于 2025-01-21 16:31:57 字数 778 浏览 0 评论 0原文

我正在使用 Selenide ,并寻找机会创建儿童elementscollection 基于父母的。例如,我有一个Web表和一个由表行组成的父元素汇总。因此,在通过某种条件过滤此集合后,我得到了50行。然后需要将第一个单元格保存为新的ElementsCollection(儿童)中的硒纤维。 如果我使用列表,此情况没有任何问题,因为我可以使用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());

但是,由于selenide 6.2.0中的stream()devect of stream()我找不到机会这样做。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无边思念无边月 2025-01-28 16:31:57

我在Gitter和Github中的专门硒化主题中提出了这个问题。我想指出,我在一个小时内收到了回应,这是项目开发和支持的非常宝贵的方法。 ))这是Selenide创始人Andrei Solntsev的答案。

我建议避免如此长的迭代等。它会导致缓慢的测试。
相反,我会写一个适当的XPath,找到所有所需的
只有一个Web驱动程序调用的元素。

我注册了添加非剥夺流()的功能请求
方法:#1773

我真的不建议这样使用迭代元素。这样的
测试高度无效。只需写一个收集条件作为
折旧通知建议。

据我所知,他将在ElementsCollection中返回未剥夺的流()。

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.

×眷恋的温暖 2025-01-28 16:31:57

您的IDE应该为您解决这个问题。由于stream()已弃用,您可以用for循环替换它,例如此

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自动生成此,如果不是您想要的,则不再依赖于stream()

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().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文