Riaz Ladhani
Riaz Ladhani

Reputation: 4062

Selenium Xpath how to find the correct checkbox I am getting 3 checkboxes selected

I have a html page with 3 checkboxes. Each text box has a text beside it. The checkboxes are nested in div tags.
I would like to select the checkbox which has the text "Clean"

My Xpath is selecting 3 checkboxes.
How do I select the checkbox which has the text Clean? It is inside the div tag with the id id="operations_edit_process_list_task_1"

My Xpath is:

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

The HTML is:

<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>

Thanks, Riaz

Upvotes: 0

Views: 499

Answers (1)

Florent B.
Florent B.

Reputation: 42528

Xpath to select the input box in the div id="operations_edit_process_list_task_2" and having the text "Clean" :

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

Or:

"//div[@id='operations_edit_process_list_task_2' and contains(.,'Clean')]//input"

Upvotes: 1

Related Questions