how to select checkbox in selenium webdriver

199 views
Skip to first unread message

Ranjeet Priyadarshi

unread,
Jun 14, 2013, 2:36:27 PM6/14/13
to webd...@googlegroups.com
I want to select a specific  checkbox using name of checkbox on UI.Please let me know how I can select a specific checkbox using Xpath.

I want to check "AAA_Automation" checkbox.

HTMLSnippet:
<div id="Who-Section" class="selected_subtab_color" style="display: block;">
<script type="text/javascript">
<table width="100%" border="0">
<div id="who_tab" class="tab-layout">
<div id="tree-form-divisionListIds">
<span id="groupTreeRoot" class="treeNode " onclick="WHO_GROUP_TREE_CONTROL.click_handler(event); whoItemSelected('divisionListIds', WHO_GROUP_TREE_CONTROL.getTreeSelectedIds('divisionListIds'))" style="white-space: nowrap;">
<span id="imgdivisionListIds" class="ndMinusBtn"></span>
<input id="divisionListIds" class="trNdChk" type="checkbox" name="divisionListIds">
Work Groups
<span id="spanWorkGroups" class="treeNode" style="display:block">
<div class="trNdElem nd-spcr ">
<div class="trNdElem nd-spcr ">
<div class="trNdElem nd-spcr ">
<div class="trNdElem nd-spcr ">
<div class="trNdElem ">
<div class="trNdElem nd-spcr ">
<input id="Division-4542662" class="trNdChk" type="checkbox" name="divisionListIds" isleaf="true">
<span class="trNdSymb-fldr"></span>
AAA_Automation
</div>
<div class="trNdElem ">
<div class="trNdElem nd-spcr ">
<div class="trNdElem nd-spcr ">
<div class="trNdElem nd-spcr ">
<div class="trNdElem nd-spcr ">
<div class="trNdElem ">
<div class="trNdElem ">
<div class="trNdElem nd-spcr ">
<div class="trNdElem nd-spcr ">
<div class="trNdElem ">
</span>
</span>
</div>
<script type="text/javascript">
</div>
</div>

darrell

unread,
Jun 16, 2013, 1:16:57 PM6/16/13
to webd...@googlegroups.com
First, if this is the actual HTML snippet, it is REALLY ugly. Having the INPUT tag nested 6 DIVs deep looks like finding the right locator is only part of the problem. If I had to automate this HTML I would have a serious talk with the developer who generated it. It looks like they don't have a proper grasp of the library they are using to generate it. 

Ignoring all the garbage around the INPUT tag you should be able to use:

    By.xpath("//input[contains(text(), 'AAA_Automation')]");
Reply all
Reply to author
Forward
0 new messages