【问题标题】:Selenium Python XPATH I am trying to find the input tag which has some text in the title attributeSelenium Python XPATH 我试图找到在标题属性中有一些文本的输入标签
【发布时间】:2016-03-03 18:04:56
【问题描述】:

我有一个 HTML 页面,其中有一些复选框,旁边有一个名称。使用 XPATH,我可以使用 = 来找到标题属性中包含完整文本的复选框以匹配完整文本。 例如

//div[@id="operations_add_process_list_tab_groups_tab_standard_1"]//span//input[@title="CRM : crm"]

我不想匹配整个文本,我想通过使用一些文本来找到它,例如我想在标题属性中找到“CRM”的复选框。 我不想使用“CRM:crm”

我可以使用 contains 关键字来查找“CRM”在标题属性中的位置吗? 我不知道这个的语法。

我试过了://div[@id="operations_add_process_list_tab_groups_tab_standard_1"]//span//input[@title[contains(text(), CRM : crm")]]

HTML 是:

<div id="operations_add_process_list_tab_groups_tab_standard_1">
<span>
<span>
<span/>
<span>
<span/>
<span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;">
    <input type="checkbox" checked="" title="CRM : crm" tabindex="-1"/>
    CRM : crm
</span>
</span>
<span>
<span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;">
    <input type="checkbox" checked="" title="ESCR : escr" tabindex="-1"/>
    ESCR : escr
</span>
</span>
<span>
<span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;">
    <input type="checkbox" checked="" title="ORCHARD : orchard" tabindex="-1"/>
    ORCHARD : orchard
</span>
</span>

谢谢, 里亚兹

【问题讨论】:

  • 试试//div[@id="operations_add_process_list_tab_groups_tab_standard_1"]//span//input[contains(@title, "CRM : crm")]

标签: python-2.7 selenium selenium-webdriver


【解决方案1】:

contains 是您正在寻找的。在你的情况下。

//input‌​[contains(@title, "CRM")]

contains 可用于任何属性,也可用于元素中的文本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    • 2019-06-04
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    相关资源
    最近更新 更多