【发布时间】:2021-08-22 10:10:39
【问题描述】:
我必须单击 selenium 中的锚标记。我申请了driver.findElement(By.xpath("//a[contains(@href,'/app/setup')")).click();
但它不起作用。
<li class="ant-menu-item" role="menuitem" style="padding-left: 24px;">
<span role="img" class="anticon">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="17" viewBox="0 0 18 18">
<path id="Icon_ionic-md-settings" >
</path>
</svg>
</span>
<span>
Setup
</span>
<a href="/app/setup">
</a>`enter code here`
</li>
【问题讨论】:
-
错误是什么?
-
INFO:检测到方言:线程“主”org.openqa.selenium.InvalidSelectorException 中的 W3C 异常:无效选择器:无法使用 xpath 表达式定位元素 //a[contains(@href,' /app/setup') 因为以下错误:SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a[contains(@href,'/app/setup')' is not a valid XPath表达。
标签: selenium hyperlink tags click anchor