【问题标题】:Selenium Webdriver XPATH I can find the label which contains certain text but I cannot get the Input tag checkbox above the Label tagSelenium Webdriver XPATH 我可以找到包含某些文本的标签,但我无法获得标签标签上方的输入标签复选框
【发布时间】:2015-10-06 16:05:48
【问题描述】:

我有一个带有复选框列表的页面。我想单击具有指定文本的复选框。 例如。我想单击名称为“使用 ocr 变体”的复选框 在 HTML 中,复选框位于标签标记上方。 在 firebug 中,我可以找到带有以下 XPath 的标签:

//div[@id="match_configuration_edit_match_tab_data_objects_fp_flags"]//label[contains(text(), "Use ocr variations")]

我想将上面的 1 转到带有复选框的输入标签。 我曾尝试使用祖先,但这不起作用

//div[@id="match_configuration_edit_match_tab_data_objects_fp_flags"]//label[contains(text(), "Use alias list to get variations")]/ancestor::input

我可以使用什么 Xpath 或 CSS 来访问复选框?

HTML 是:

<div id="match_configuration_edit_match_tab_data_objects_fp_flags">
    <div class="gwt-Label matchruleheader">Gender and title flags</div>
        <span class="gwt-CheckBox" style="display: block;">
        <span class="gwt-CheckBox" style="display: block;">
        <span class="gwt-CheckBox" style="display: block;">
    <div class="gwt-Label matchruleheader">Name flags</div>
        <span class="gwt-CheckBox" style="display: block;">
        <span class="gwt-CheckBox" style="display: block;">
    <div class="gwt-Label matchruleheader">Other flags</div>
    <span class="gwt-CheckBox" style="display: block;">
    <span class="gwt-CheckBox" style="display: block;">
        <input id="gwt-uid-512" type="checkbox" value="on" tabindex="0" checked=""/>
        <label for="gwt-uid-512">Use alias list to get variations</label>
    </span>
    <span class="gwt-CheckBox" style="display: block;">
        <input id="gwt-uid-513" type="checkbox" value="on" tabindex="0" checked=""/>
        <label for="gwt-uid-513">Use ocr variations</label>
    </span>
</div>

注意:复选框的输入 id 是一个动态值。我不能用那个。 输入 id="gwt-uid-513" 谢谢, 里亚兹

【问题讨论】:

    标签: css selenium xpath selenium-webdriver


    【解决方案1】:

    ancestor 用于父/授予父元素。作为您在同一级别中寻找的“输入”元素,您可以使用preceding

    【讨论】:

    • 谢谢,我已经用previous了。
    • //div[@id="match_configuration_edit_match_tab_data_objects_fp_flags"]//label[contains(text(), "使用别名列表获取变体")]/preceding::input[1]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多