Search code examples
testingprotractorend-to-end

Protractor - Verify that element exist


i am using some kind of angular filter of a table and i need to verify if results from filter is correct.

I already work with this table before, where I click on element:

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

this basicly click on element where <td> have value 89. I need to verify that this number is still there after I enter for example number 8 to filter So i write this:

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

Unfortunately I get an error:

Object [object Object] has no method 'isPresent'

I didn't find any other method how to verify if something exist, is there some problem in syntax or is there any other method which can replace isPresent?


Solution

  • isPresent is available only for ElementFinder, not for ElementArrayFinder, so you should not call it after you've used all:

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

    If you really want to use all, try with count() instead:

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