【问题标题】:Selenium xpath - Unable to find the xpathSelenium xpath - 无法找到 xpath
【发布时间】:2023-03-06 16:30:01
【问题描述】:

我需要从下面的 html 中获取文本“未找到结果,单击选项卡以使用输入的文本”。

<div id="boundlist-1520-listEl" class="x-boundlist-list-ct" style="overflow: auto; height: auto;">
<ul></ul>
No results found, click tab to use entered text
</div>

当我尝试使用 div id 时,它会抛出错误。

谁能帮我得到这个的xpath。

非常感谢。

问候, 苏达巴纳卡

【问题讨论】:

  • 您遇到的错误是什么?添加您正在使用的 xpath
  • 您使用的是哪个 Selenium 客户端 Java/Python/C# ?
  • id 似乎是动态的,尝试使用 classname x-boundlist-list-ct

标签: selenium


【解决方案1】:

我猜您的 id 是动态更改的,因此您需要通过 start with 或 contains 方法来识别它。以下 XPath 将为您工作

"//div[starts-with(@id,'boundlist-')]

您可以通过将 XPath 粘贴到您的 google chrome 控制台来验证它

$x("//div[starts-with(@id,'boundlist-')]")

【讨论】:

    【解决方案2】:

    xpath 是:- //ul[contains(text(),'没有找到结果,点击tab使用输入的文本')]

    或者最好是 //*[contains(text(),'没有找到结果,点击tab使用输入的文本')]

    【讨论】:

      【解决方案3】:

      如果显示的文本没有改变,那么你可以在 xpath 下面使用

      //div[text()='No results found, click tab to use entered text']
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-27
        相关资源
        最近更新 更多