I have a table whose HTML code is as below. I want to click on the checkbox in the row that contains "Base User" (i.e in tr[5]). I am not able to click on the checkbox. I am using firefox browser and Selenium Webdriver (Java)
<div class="ui-jqgrid-bdiv" style="height: 340px; width: 440px;">
<div style="position:relative;">
<div></div>
<table id="s_4_l" class="ui-jqgrid-btable" border="0" cellspacing="0" cellpadding="0" tabindex="0" role="grid" aria-multiselectable="true" aria-labelledby="" style="width: 439px;" summary="Responsibilities" datatable="1">
<tbody>
<tr class="jqgfirstrow" style="height:auto" role="row">
<tr id="1" class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" role="row" style="height: 32px;">
<tr id="2" class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" role="row" style="height: 32px;">
<tr id="3" class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" role="row" style="height: 32px;">
<tr id="4" class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" role="row" style="height: 32px;" aria-selected="false">
<tr id="5" class="ui-widget-content jqgrow ui-row-ltr ui-state-highlight selected-row ui-state-hover" tabindex="-1" role="row" style="height: 32px;" aria-selected="true">
<td aria-describedby="s_4_l_cb" style="text-align:center;display:none;" role="gridcell">
<input id="jqg_s_4_l_5" class="cbox" type="checkbox" role="checkbox">
</td>
<td id="5_s_4_l_SSA_Primary_Field" class="edit-cell ui-state-highlight" title="Unchecked" style="text-align:center;" role="gridcell" aria-labelledby="s_4_l_SSA_Primary_Field s_4_l_altCheckBox" tabindex="0">
<span tabindex="-1">
<input id="5_SSA_Primary_Field" class="customelement siebui-ctrl-checkbox siebui-align-center siebui-input-align-center s_4_2_82_0" type="checkbox" aria-checked="false" value="N" tabindex="0" role="checkbox" name="SSA_Primary_Field" maxlength="1" aria-labelledby="5_s_4_l_Name s_4_l_SSA_Primary_Field s_4_l_altCheckBox">
</span>
</td>
<td id="5_s_4_l_Name" title="Base User" style="text-align:left;" role="gridcell" aria-labelledby="s_4_l_Name">Base User</td>
<td id="5_s_4_l_Organization" title="Canada" style="text-align:left;" role="gridcell" aria-labelledby="s_4_l_Organization">Canada</td>
</tr>
<tr id="6" class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" role="row" style="height: 32px;">
<td aria-describedby="s_4_l_cb" style="text-align:center;display:none;" role="gridcell">
<td id="6_s_4_l_SSA_Primary_Field" title="Checked" style="text-align:center;" role="gridcell" aria-labelledby="s_4_l_SSA_Primary_Field s_4_l_altCheckBox">
<span class="siebui-icon-checkbox-checked">
<img hspace="0" border="0" space="0" title="Selected" alt="Selected" src="XYZ.com/images/check_d.gif">
</span>
<span style="display:none;">Y</span>
</td>
<td id="6_s_4_l_Name" title="Product Administrator" style="text-align:left;" role="gridcell" aria-labelledby="s_4_l_Name">Product Administrator</td>
<td id="6_s_4_l_Organization" title="Canada" style="text-align:left;" role="gridcell" aria-labelledby="s_4_l_Organization">Canada</td>
</tr>
<tr id="7" class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" role="row" style="height: 32px;">
</tbody>
</table>
This table contains 7 rows and the first column has a checkbox in each row. Only one row has the checkbox CHECKED/TICKED at any given time, here it is the 6th row. For other rows, the checkbox is not displayed. Only when you click somewhere within the area of the first cell of a row, the checkbox will be displayed for that row. Then you can tick on that checkbox. Therefore I have clicked on the first cell of the 5th row and now the checkbox is displayed (as shown in my code below).
How do I click on this checkbox of the 5th row? My code is below, the third line is the one I am trying to click on the checkbox, but it does not click.
WebElement primaryCell = driver.findElement(By.xpath("/html/body/div[9]/div[2]/div/div/div/div[3]/form/div[1]/div/div/div[3]/div[3]/div/table/tbody/tr/td[contains(text(),'Base User')]/preceding-sibling::td[@title='Unchecked']"));
primaryCell.click();
primaryCell.findElement(By.xpath("//span/input")).click();
Please help, Thanks!
Please note that the @id of tagnames-table, tr, td - are not static and keep changing. I have tried using the solutions provided in some existing posts, but I could not resolve my issue.