CSS containing exact text
You can solve this with cssContainingText
as well if you use a regexp with an exact match for the second argument, e.g.:
element(by.cssContainingText('option', /^Value 1$/))
See related SO post here: Match whole string
The by.cssContainingText()
is a partial match locator by definition. If you want to have an exact match, you can solve it with an XPath expression:
element(by.xpath('//option[. = "Value 1"]')).click();
And, since you are dealing with select
and option
s, see if this wrapper would be a good fit:
- Select -> option abstraction