【问题标题】:Unable to locate an href element with an active child span Selenium WebDriver无法找到具有活动子跨度 Selenium WebDriver 的 href 元素
【发布时间】:2017-11-16 23:29:52
【问题描述】:

我的 AUT 中有几个 html 元素,格式如下:

<a href="#home">HOME<span class="activeChild">&nbsp;&gt; Payments</span></a>

span 子元素根据当前活动页面不断变化的位置。

很明显,Selenium WebDriver 没有合适的唯一定位器。我最终的唯一方法是使用链接文本或使用 href 构建 xpath。

"//a[(@href='#home')]" 不起作用,尽管它在页面中是唯一的。

谁能帮我找到这个元素?

【问题讨论】:

    标签: java selenium xpath selenium-webdriver css-selectors


    【解决方案1】:

    你可以试试这个 xpath :- //a[starts-with(@href, "#home")]//a[starts-with(text(), "Home")]

    【讨论】:

    • 谢谢 Ankur。这似乎奏效了。我会玩一会儿。再次感谢。
    猜你喜欢
    • 2016-07-02
    • 2016-08-13
    • 2014-05-29
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    相关资源
    最近更新 更多