Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between isPresent and isElementPresent [duplicate]

What's the difference between ElementFinder.prototype.isPresent and ElementFinder.prototype.isElementPresent?

It sounds like isElementPresent waits for Angular to finish, while isPresent just does a check immediately, but I can't tell for sure.

Currently, isElementPresent is broken as per a Protractor bug, so I can't manually test the difference.

like image 448
Mitchell Hentges Avatar asked Oct 31 '22 12:10

Mitchell Hentges


1 Answers

Both isPresent and isElementPresent return an "Element Finder" which:

"represents a single element of an ElementArrayFinder (and is more like a convenience object). As a result, anything that can be done with an ElementFinder, can also be done using an ElementArrayFinder. The ElementFinder can be treated as a WebElement for most purposes, in particular, you may perform actions (i.e. click, getText) on them as you would a WebElement."

Reader's Digest version: You can call methods on it or test if it exists.

isElementPresent actually calls isPresent if the locator is met, see the return statement: enter image description here

They essentially do the same thing. Protractor is built on top of WebDriver, which has its own methods. You can also use these methods in Protractor. In the event that testing Angular with these methods could result in faulty information, they provided users with an Angular work-around; isElementPresent is one of those, for the reason you mentioned.

tl;dr: Use isPresent. It was built for Protractor to test Angular.

like image 70
Adam Avatar answered Nov 09 '22 08:11

Adam