我有 2 个 ElementsCollections
,即 oddTableRowItems
和 evenTableRowItems
:
private static ElementsCollection oddTableRowItems() {
return $$(By.className("odd"));
}
private static ElementsCollection evenTableRowItems() {
return $$(By.className("even"));
}
我想将两者结合起来,以便只执行一次 for 循环。它是行项目,只有类名出于样式目的而有所不同,我只能通过类名来识别它们。
这就是我尝试组合它的方式 - 但它不起作用:
ElementsCollection rowElements = evenTableRowItems();
rowElements.addAll(oddTableRowItems());
我得到一个:
java.lang.UnsupportedOperationException
有谁知道如何组合 2 个 ElementsCollections
吗?
最佳答案
这里的 API 可能会更友好一些。但通过这种方式,您可以组合两个 ElementsCollection 实例。这里的关键是 WebElementsCollectionWrapper
类。
ElementsCollection evenElements = $$(By.className("even"));
ElementsCollection oddElements = $$(By.className("odd"));
List<SelenideElement> elementsCombined = new ArrayList<>(evenElement);
elementsCombined.addAll(oddElements);
WebElementsCollectionWrapper wrapper = new WebElementsCollectionWrapper(elementsCombined);
ElementsCollection selenideCollectionCombined = new ElementsCollection(wrapper);
关于selenium - Selenide 结合了 2 个 ElementsCollections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34336081/