硒网络驱动程序找到锚点标签并单击
2022-09-03 12:36:11
<div id="ContentPrimary">
<ul class="selectors modeSelectors">
<li><a href="/content/l411846326l1213g/references/" title="">
<span class="selector">References (27)</span></a></li>
<li><a href="/content/l411846326l1213g/referrers/" title="">
<span class="selector">Cited By (2)</span></a></li>
<li><a href="/content/l411846326l1213g/export-citation/" title="">
<span class="selector">Export Citation</span></a></li>
<li><a href="/content/l411846326l1213g/about/" title="">
<span class="selector">About</span></a></li>
</ul>
在这里,我需要找到并单击使用Selenium api的“关于”链接,但我无法做到这一点。
我做的是
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver webDriver) {
System.out.println("Searching ...");
String s = driver.findElement(By.cssSelector("#ContentPrimary ul li[4] span.selector")).getText();
System.out.println(s);
if (Pattern.compile(Pattern.quote("About"), Pattern.CASE_INSENSITIVE).matcher(s).find()) {
return true;
} else {
return false;
}
}
});
driver.findElement(By.linkText("About")).click();
但它不起作用