【问题标题】:Need help in writing XPATH for Selenium with Python在使用 Python 为 Selenium 编写 XPATH 时需要帮助
【发布时间】:2017-09-29 13:42:19
【问题描述】:

下面是DOM中的元素。

<div style="float:left;width: 40px">
<label class="radio inline">
<input id="formData99991:Select" class="sample" data-ng-model="sampletId" size="" name="formData99991Select" sample-value="true" style="" value="1234" checked="checked" type="radio"/>
A
</label>
</div>

我尝试使用//input[contains(@id,'formData99991:Select') and contains(text(),'A')],但它不起作用。 网页上有多个相似的元素,我需要用 id 和 text 的组合来识别每个元素。

【问题讨论】:

  • 可以分享你的html代码吗?
  • 我把它贴在了问题中。但是,它没有出现在这里..请在下面找到
  • 为什么不使用 firepath 作为 firebug,这样您就可以检查元素并直接为您提供正确的 xpath?

标签: python selenium


【解决方案1】:

您可以尝试使用以下 x-path,

//label[contains(.,'A')]/input[@id="formData99991:Select"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多