Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS containing exact text

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();
like image 621
NewWorld Avatar asked Nov 02 '16 13:11

NewWorld


People also ask

Is there a CSS selector for elements containing certain text?

CSS [attribute~=value] Selector The [attribute~=value] selector is used to select elements with an attribute value containing a specified word.

How do I use contains in CSS locator?

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.


1 Answers

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

like image 160
matsr Avatar answered Sep 25 '22 15:09

matsr