当前位置: 首页 > 知识库问答 >
问题:

Selenium Xpath如何找到正确的复选框我选择了3个复选框

羊舌富
2023-03-14

我有一个带有3个复选框的html页面。每个输入框旁边都有一个文本。复选框嵌套在div标签中。
我想选择具有文本“清洁”的复选框

我的Xpath正在选择3个复选框
如何选择清除文本的复选框?它位于id为=“operations\u edit\u process\u list\u task\u 1”的div标记内

我的Xpath是:

//div[@id="operations_edit_process_list_task_1"]//span[text()="Clean"]//following::span[@title="Turn group off or on."]/input[1]

超文本标记语言是:

<div id="operations_edit_process_list_task_1">
<span>
<span/>
<span>
<span title="Turn group off or on." style="">
<input type="checkbox" checked="" tabindex="-1"/>
</span>
</span>
<span/>
</div>
</div>
</div>
</div>
</div>
</div>
<div style="overflow: hidden; display: none;"/>
</div>
<div aria-selected="false" role="treeitem" aria-setsize="3" aria-posinset="2" aria-expanded="false" aria-level="1">
    <div class="GJPPK2LBIF GJPPK2LBAG" style="padding-left: 0px;">
        <div class="GJPPK2LBIF GJPPK2LBKF GJPPK2LBCG" style="padding-left: 16px;position:relative;" onclick="">
            <div class="GJPPK2LBJF GJPPK2LBBG" style="left: 0px;width: 15px;height: 15px;position:absolute;">
                <div class="GJPPK2LBLF">
                    <div style="padding-left: 22px;position:relative;zoom:1;">
                        <div style="left:0px;margin-top:-8px;position:absolute;top:50%;line-height:0px;">
                            <div>
                                <div id="operations_edit_process_list_task_2">
<span>
<span class="myinlineblock" title="Match"
      style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;width:100%;">Match</span>
</span>
                                    <span/>
<span>
<span title="Turn group off or on." style="">
<input class="" type="checkbox" checked="" tabindex="-1"/>
</span>
</span>
                                    <span/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div aria-selected="false" role="treeitem" aria-setsize="3" aria-posinset="3" aria-expanded="false"
             aria-level="1">
            <div class="GJPPK2LBIF GJPPK2LBAG" style="padding-left: 0px;">
                <div class="GJPPK2LBIF GJPPK2LBKF GJPPK2LBCG" style="padding-left: 16px;position:relative;" onclick="">
                    <div class="GJPPK2LBJF GJPPK2LBBG" style="left: 0px;width: 15px;height: 15px;position:absolute;">
                        <div class="GJPPK2LBLF">
                            <div style="padding-left: 22px;position:relative;zoom:1;">
                                <div style="left:0px;margin-top:-8px;position:absolute;top:50%;line-height:0px;">
                                    <div>
                                        <div id="operations_edit_process_list_task_3">
<span>
<span class="myinlineblock" title="PossMatch"
      style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;width:100%;">PossMatch</span>
</span>
                                            <span/>
<span>
<span title="Turn group off or on." style="">
<input class="" type="checkbox" checked="" tabindex="-1"/>
</span>
</span>
                                            <span/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

谢了Riaz

共有1个答案

左康安
2023-03-14

Xpath选择div id=“operations\u edit\u process\u list\u task\u 2”中的输入框,并具有文本“Clean”:

"//div[@id='operations_edit_process_list_task_2'][.//span='Clean']//input"

或:

"//div[@id='operations_edit_process_list_task_2' and contains(.,'Clean')]//input"
 类似资料:
  • 问题内容: 我有一个包含3个复选框的表单:“ 全 选 ”,“ 选项1 ”和“ 选项2 ”。 在初始页面加载中,我 只 希望检查 选项1 。然后,如果 选中了“全选” 复选框,则它应自动选中 选项1 和 选项2, 以便全部选中。 问题是在初始页面加载时对ng-checked =“ selectAll”进行评估,这将覆盖我最初仅检查选项1的尝试(最初selectAll = false),因此未选择任何

  • 问题内容: 我如何在PHP 中检查是否选中a ? 问题答案: 如果选中该复选框,则将传递该复选框的值。否则,该字段不会在HTTP帖子中传递。

  • 如果选中复选框D并取消选中其他复选框,我希望选中复选框K和F。同样,如果选中复选框I,则前面的复选框I将被选中,下面的复选框将被取消选中。我的html代码是: 我为此所做的是: 这看起来很乱,还有一个很酷的过程吗???

  • 我想调用一个函数时,选择的任何选项。类似于这样: 但不知何故不起作用。有人能帮忙吗。 请注意 我不想捕获更改事件,如果我选择已经选择选项,则不会触发更改事件

  • 如果数据库中的数据为是或否,如何选中复选框,我尝试使用attr函数,但没有成功 这是我的html

  • 我想允许至少3个复选框将检查,我试过下面的代码但它不是很好地工作。 HTML... jQuery 有人请帮助我,我如何选择至少2个复选框?