【问题标题】:Automation: Selenium: unable to click anchor tag自动化:Selenium:无法单击锚标记
【发布时间】: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


【解决方案1】:

正如您的错误所示,您指定的 xpath 无效。您缺少 contains 的右括号。 你有

"//a[contains(@href,'/app/setup')"

应该是

"//a[contains(@href,'/app/setup')]"

【讨论】:

    猜你喜欢
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 1970-01-01
    • 2023-03-19
    • 2017-03-30
    • 1970-01-01
    相关资源
    最近更新 更多