Reputation: 31
I am trying to select based on text, I use the following to select
$("div[class='ui-datatable-tablewrapper']").find("span:contains('Person Name')")
i get the following error:
Caused by: org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified
I believe it's because of the "contains" selector in jquery. How do I achieve the same in geb.
Html:
<div class="ui-datatable-tablewrapper">
<table role="grid">
<thead id="searchForm:singleStaffDT_head">
<tr role="row">
<th id="searchForm:singleStaffDT:j_id_7s" class="ui-state-default" role="columnheader"
aria-label="Person ID" scope="col" style="width:15%">
<span class="ui-column-title">Person ID</span>
</th>
<th id="searchForm:singleStaffDT:j_id_7u" class="ui-state-default" role="columnheader"
aria-label="Person Name" scope="col" style="width:25%">
<span class="ui-column-title">Person Name</span>
</th>
<th id="searchForm:singleStaffDT:j_id_7w" class="ui-state-default" role="columnheader"
aria-label="Organization" scope="col" style="width:25%">
<span class="ui-column-title">Organization</span>
</th>
<th id="searchForm:singleStaffDT:j_id_7y" class="ui-state-default" role="columnheader"
aria-label="Staff Role" scope="col" style="width:25%">
<span class="ui-column-title">Staff Role</span>
</th>
<th id="searchForm:singleStaffDT:j_id_80" class="ui-state-default" role="columnheader"
aria-label="" scope="col" style="width:10%">
<span class="ui-column-title">Action
<BR />[Select]</span>
</th>
</tr>
</thead>
<tbody id="searchForm:singleStaffDT_data" class="ui-datatable-data ui-widget-content">
<tr class="ui-widget-content ui-datatable-empty-message">
<td colspan="5"></td>
</tr>
</tbody>
</table>
</div>
Upvotes: 0
Views: 3124
Reputation: 889
For a "contains" search, you want to write your code in a similar pattern to this:
$("span", text: contains("Person Name"))
You could also do something like this in your page object (i think!):
personName { $('span').find(text: 'Person Name') }
Or:
personName { find('span', text: 'Person Name') }
Upvotes: 3