I want to use two identifiers for the same element and use the first one found. With Java, we have @findAll. Is there any way to that with javascript protractor?

Any function/options or something relative?

2 Answers 2


Unfortunately, there are no decorators in JavaScript.

What you can do is to locate multiple elements and then use .first():

var MyPageObject = function () {
    this.multipleElement = element.all(by.css(".someclass"));
    this.firstElement = this.multipleElements.first();

This way, you are not repeating locators and following the DRY principle.


finally I did this easy function:

function locateElement(desktopLocator, mobileLocator)
    var locator = "";
    if(browser.platform === "Desktop") 
        return desktopLocator;
        return mobileLocator;

myProfileTab: locateElement(element(by.tagName('element1')), element(by.tagName('element2')))

It Works perfectly now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.