Zack Zatkin-Gold
Zack Zatkin-Gold

Reputation: 824

element.all(locator).first() vs element(locator) with warning?

During the build process of an application I'm working on, I have been getting warnings about element(locator) returning more than one result, with the first matching element being returned.

Would the build process speed up if I were to do element.all(locator).first()?

Upvotes: 2

Views: 476

Answers (1)

alecxe
alecxe

Reputation: 473873

According to the source code, first() is basically calling get(0) on a ElementArrayFinder. get(index) would not make protractor search for a single element at a specified index, instead - protractor would first ask the webdriver find all of the elements matching a locator and only then retrieve an element at a specified index. There is no special handling or performance improvement for the first element at the 0 index.

Upvotes: 1

Related Questions