0
votes

I'm working with to automate a GWT app. There is a table with the following columns: checkbox, userID, Username, Fname, LName, Email.

Here's the code for a single row in the table:

</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td class="GB1F3LJFQ GB1F3LJKO" title="8902" align="right" style="height: 19px; width: 34px;">
<div style="height: 19px; width: 34px;">
<div class="gwt-HTML">8902</div>
</div>
</td>
<td class="GB1F3LJFQ GB1F3LJKO" title="Agency_Group_0_Agency_Group_Member_0_dan_all_features_6" align="left" style="height: 19px; width: 146px;">
<div style="height: 19px; width: 146px;">
<div class="gwt-HTML">Agency_Group_0_Agency_Group_Member_0_dan_all_features_6</div>
</div>
</td>
<td class="GB1F3LJFQ GB1F3LJKO" title="" align="left" style="height: 19px; width: 63px;">
<div style="height: 19px; width: 63px;">
<div class="gwt-HTML">

</div>
</div>
</td>
<td class="GB1F3LJFQ GB1F3LJKO" title="" align="left" style="height: 19px; width: 28px;">
<div style="height: 19px; width: 28px;">
<div class="gwt-HTML">

</div>
</div>
</td>
<td class="GB1F3LJFQ GB1F3LJKO" title="[email protected]" align="left" style="height: 19px; width: 146px;">
<div style="height: 19px; width: 146px;">
<div class="gwt-HTML">[email protected]</div>
</div>
</td>
</tr>
</tbody>
</table>

The xpath to the checkbox is: /html/body/div[6]/div/table/tbody/tr[2]/td[2]/div/div/div/div/table/tbody/tr[2]/td/div/div/div/div[1]/div/table[10]/tbody/tr/td[1]

The xpath to the username column is: /html/body/div[6]/div/table/tbody/tr[2]/td[2]/div/div/div/div/table/tbody/tr[2]/td/div/div/div/div[1]/div/table[10]/tbody/tr/td[3]

My code loops through a list of names and it is supposed to click the checkbox associated with that name: for name in memberlist: print 'clicking checkbox associated with %s' %name chrome.find_element_by_xpath("//tr[td[contains(text()='" + name + "')]]/td[1]").click()

The error I'm getting is: selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //tr[td[contains(text()='Agency_Group_0_Agency_Group_Member_0_dan_all_features_6')]]/td[1] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//tr[td[contains(text()='Agency_Group_0_Agency_Group_Member_0_dan_all_features_6')]]/td[1]' is not a valid XPath expression. (Session info: chrome=48.0.2564.116)

My question is: How do I click the checkbox associated with the name?

1
Probably sometimes you need to mouse over it and then go ahead and click it. You know sometimes objects are not directly enabled, until mouse is hoovered on it.Srekk

1 Answers

1
votes

You not using contains() correctly. Replace:

//tr[td[contains(text()='" + name + "')]]/td[1]

with:

//tr[td[contains(text(), '" + name + "')]]/td[1]