如何在Proctractor中显示文本

时间:2016-05-04 10:49:18

标签: javascript angularjs automation jasmine protractor

如何在第二个td中显示文本。

<tr data-ng-repeat="s in systemSettings" class="ng-scope">
        <td class="ng-binding">License Key</td>
        <td class="ng-binding">rashmi123</td>
        <td align="center">
            <div data-ng-show="s.readOnly" class="text-warning ng-hide">read only</div>
            <div data-ng-show="!s.readOnly"> <a href="" data-ng-click="onSettingEdit(s)"><i class="glyphicon glyphicon-edit"></i> </a> </div>
        </td>
    </tr>

我试图通过

使用它
  expect(element("tr:nth-child(2) td.ng-binding:nth-child(2)").getInnerHtml()).toBe("rashmi123");

但是它给出了无效的定位器错误。

1 个答案:

答案 0 :(得分:2)

您的元素定位器应包含类似 - xpathcss等类型...

expect(element(by.css("tr:nth-child(2) td.ng-binding:nth-child(2)")).getInnerHtml()).toBe("rashmi123");

此外,您可以使用.getText()来获取元素的文本而不是getInnerHtml。

var ele = element(by.css("tr:nth-child(2) td.ng-binding:nth-child(2)"));
expect(ele.getText()).toBe("rashmi123");

或者使用量角器提供的缩写形式element(by.css()) =&gt; $()

var ele = $("tr:nth-child(2) td.ng-binding:nth-child(2)");
expect(ele.getText()).toBe("rashmi123");

希望它有所帮助。