量角器 - 验证元素是否存在

Protractor - Verify that element exist

我正在使用 table 的某种 angular 过滤器,我需要验证过滤器的结果是否正确。

我之前已经使用过这个 table,我在其中单击元素:

element.all(by.xpath('.//td[.="89" and @class="ultranarrow ng-binding"]')).click();

这基本上是单击 <td> 值为 89 的元素。在我输入例如数字 8 进行过滤后,我需要验证该数字是否仍然存在所以我这样写:

expect(element.all(by.xpath('.//td[.="89" and @class="ultranarrow ng-binding"]')).isPresent()).toBe(true);

不幸的是我得到一个错误:

Object [object Object] has no method 'isPresent'

我没有找到任何其他方法来验证是否存在某些东西,是否存在语法问题或是否有任何其他方法可以替代 isPresent?

我不确定,但我认为你不能 element.all(by.xpath(''));
所以你可以试试::::

expect(element(by.xpath('.//td[.="89" and @class="ultranarrow ng-binding"]')).isPresent()).toBe(true); 

或选择不同的定位器

expect(element.all(by.css('td[class="ultranarrow ng-binding"]')).isPresent()).toBe(true);

isPresent 仅适用于 ElementFinder,不适用于 ElementArrayFinder,因此您不应在使用 all:

后调用它
expect(element(by.xpath('.//td[.="89" and @class="ultranarrow ng-binding"]')).isPresent()).toBe(true); 

如果您真的想使用 all,请尝试使用 count()

expect(element.all(by.xpath('.//td[.="89" and @class="ultranarrow ng-binding"]')).count()).toBe(1);