user9919998
user9919998

Reputation: 41

cannot find css element in protractor

How do I locate the element with the following html, I have 4 Start buttons each in different color. I tried using css by class and is not working. There are no unique ids as well. Pls help

Start

Upvotes: 0

Views: 33

Answers (1)

Jeremy Kahan
Jeremy Kahan

Reputation: 3826

As Ben Mohorc points out, you really need to give us a bit more to go on. But if you are saying there are multiple start buttons, but only one of each color, it ought to look like this. For now I assume all they say is "Start". If that is only part of what they say, use partial buttontext.If it is background color that differs, you may need to adapt that, too.

var coloredButton = element.all(by.buttonText('Start')).filter(function(elem) {
    return elem.getCssValue('color').then(function(color) {
        return (color == '#00ff00')//fill in the desired color here, in this format
    })
});

Then do your stuff on coloredButton.first(), which will be the only one, according to what you are saying. For more on the format to expect from the color, see http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.getCssValue

Upvotes: 0

Related Questions