All function in a similar way with subtle differences. Here are few differences that i found –
- Is an extension of
ElementFinder
and so waits for Angular to settle on page before executing any action. - It works when
elm
is anelement(locator)
orElementFinder
and notElementArrayFinder
. If multiple elements are returned using thelocator
specified then first element is checked if itisEnabled()
in the DOM. Doesn’t take any parameter as input. - Works best with Angular pages and Angular elements.
- First preference to use whenever there is a need to find if an element is present.
elm.isElementPresent(subLoc)
– (When there is a sub locator to elm
)
- Is an extension of
ElementFinder
and so waits for Angular to settle on page before executing any action. - Used to check the presence of elements that are sub elements of a parent. It takes a
sub locator
to the parentelm
as a parameter. (only difference between this and theelm.isPresent()
) - Works best with Angular pages and Angular elements.
- First preference to use whenever there is a need to check if a sub element of a parent is present.
browser.isElementPresent(element || Locator)
–
- Is an implementation of
webdriver
and so doesn’t wait for angular to settle. - Takes a
locator
or anelement
as a parameter and uses the first result if multiple elements are located using the same locator. - Best used with Non-Angular pages.
- First preference to use when testing on non-angular pages.
All of the above checks for the presence of an element in DOM and return a boolean
result. Though angular and non-angular features doesn’t affect the usage of these methods, but there’s an added advantage when the method waits for angular to settle by default and helps avoid errors in case of angular like element not found or state element reference exceptions, etc…