这是方法本身
private static WebElement findByOneCss (WebElement we, String selector) {
try {
return we.findElement (By.cssSelector (selector));
} catch (NoSuchElementException e) {
return null;
}
}
我知道您需要更改为 findElement findElements 但不考虑所有 View 。
我有一个循环绕过他这里的值
for (WebElement wle: wlElements) {
WebElement commenWe = findByOneCss (wle, ".activity-new-val");
wl.setReason1 (commenWe! = null? commenWe.getText (): "");
wlList.add (wl);
}
它需要改变什么,我试着喜欢这个
List <WebElement> commenWe = findAllByOneCss (wle, ".activity-old-val");
wl.setReason (commenWe! = null? ((WebElement) commenWe) .getText (): "");
wlList.add (wl);
但它克服了 java.util.ArrayList 无法转换为 org.openqa.selenium.WebElement 的错误
最佳答案
根据 wlList
的类型,您可以使用:wlList.addAll(commenWe);
或者你迭代commenWe喜欢这样:
List<WebElement> commenWe = findAllByOneCss(wle, ".activity-old-val");
for (WebElement we : commenWe) {
//whatever [wl] is...
wl.setReason(we!=null ? ((WebElement) we).getText(): "");
wlList.add(wl);
}
关于java - 更改方法findByOneCss,他收到了不止一种含义和所有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32819445/