我正在尝试将页面上带有标签的所有Web元素复制到列表中。我没有收到以下代码的任何编译错误,并且也没有将任何Web元素检索到列表中。有人可以检查并帮助这段代码有什么问题吗?
public WebElement clickLinkByHref(String href) {
System.out.println("Function called");
WebElement anchor = null;
List<WebElement> anchors = driver.findElements(By.tagName("a"));
System.out.println("Anchor is "+anchor);
Iterator<WebElement> i = anchors.iterator();
while(i.hasNext()) {
anchor = i.next();
if(anchor.getAttribute("href").contains(href)) {
break;
}
}
System.out.println("Anchor is "+anchor);
return anchor;