Geb根据文本选择标签

时间:2018-07-24 06:48:14

标签: selenium groovy geb

我正在尝试基于文本进行选择,我使用以下内容进行选择

$("div[class='ui-datatable-tablewrapper']").find("span:contains('Person Name')")

我收到以下错误:

Caused by: org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified

我相信这是因为jquery中的“包含”选择器。我如何在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>

1 个答案:

答案 0 :(得分:3)

对于“包含”搜索,您希望以与此类似的模式编写代码:

const int16x8_t max_value = vdupq_n_s16(255);
const int16x8_t min_value = vdupq_n_s16(0);
int16x8_t q_result = ...;
q_result = vmaxq_s16(min_value, q_result);
q_result = vminq_s16(max_value, q_result);

您还可以在页面对象中执行类似的操作(我认为!):

$("span", text: contains("Person Name"))

或者:

    personName { $('span').find(text: 'Person Name') }