Can someone please suggest if there is any way to search for an element with exact text while using cssContainingText. I am using below code but have multiple values in dropdown as below.
Value 1
Value 1 Test 1
Value 1 Protractor 1
Below is the code I am using.
element(by.cssContainingText('option', Value1)).click();
CSS [attribute~=value] Selector The [attribute~=value] selector is used to select elements with an attribute value containing a specified word.
For locating elements by using their text contents, CSS selectors and XPath provide methods to find text within the elements. If an element contains specific text, this will return the element back to the test. The contains() pseudo-class accepts the text to be searched as a parameter.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With