量角器 - 从表中获取文本

时间:2015-06-29 14:55:48

标签: javascript testing selenium-webdriver protractor end-to-end

我在表格中列出了“个案”,我需要通过NAME找到特定的一个并点击它。

我的HTML看起来像:

<tr ng-repeat-start="case in cases | orderBy:order:order_reverse" class="middle ng-scope odd readonly" ng-class-odd="'odd'" ng-class-even="'even'" ng-class="{readonly: !caseManager.isWritable(case)}">
                    <td>
                        <span ax-sharing-circle="SHARED_WITH_PARTNER" class="ng-isolate-scope"><span class="icon sharing-circle sharing-circle-left" title="Sdílený"></span></span>
                    </td>
                    <td class="case-table-claim-number fix-v-align">
                        <a ui-sref="case.general({caseId: case.caseId})" class="ng-binding" href="#/case/0a0b1c2a-94b4-444c-a2b8-c62cbd3532ae/general">20150629-165000-65</a>
                    </td>
                    <td class="case-table-claim-number fix-v-align ng-binding"></td>
                    <td class="case-table-claim-number fix-v-align ng-binding"></td>
                    <td class="case-table-make fix-v-align ng-binding"></td>
                    <td class="case-table-make fix-v-align ng-binding"></td>
                    <td class="case-table-status fix-v-align ng-binding">
                        29.6.2015
                    </td>
                    <td class="case-table-status fix-v-align ng-binding"></td>
                    <td>
                        <span class="glyphicon glyphicon-menu-down" ng-class="{
                                'glyphicon glyphicon-menu-up': hasOverview(case.caseId),
                                'glyphicon glyphicon-menu-down': !hasOverview(case.caseId),
                              }" ng-click="toggleOverview(case.caseId)"></span>
                    </td>
                </tr>

在上面的示例中,您可以找到字符串20150629-165000-65,它是案例的名称。

我尝试写这样的东西:

element(by.cssContainingText('a', global.caseNumber)).click();

应找到元素并单击它,而不是它抛出错误:

  

使用定位器找不到任何元素:by.cssContainingText(“a”,“20150629-165000-65”)

有人可以告诉我怎么做吗?

1 个答案:

答案 0 :(得分:1)

有一个适合用例的相关by.linkText()定位器:

var link = element(by.linkText(global.caseNumber));

如果仍然找不到所需的元素,请尝试添加等待:

var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(link), 5000);