I have a drop down box and I want to locate element by span value. How to do this? I don't want to use xpath as it is not a best practice.
Asked
Active
Viewed 5,876 times
1
-
Does the span value here mean the text content displayed between span tag? If so, you have to use xpath, because css selector not support to find element by its text content. – yong May 29 '18 at 09:38
-
yes. 100. here i want to use 100. only this value is unique here. – Cynthia May 29 '18 at 09:49
-
There is an id attribute. Why don't you want to use it? – demouser123 May 29 '18 at 09:56
1 Answers
4
Option 1
element(by.cssContainingText('span.mat-option-text', '100'))
Option 2
element(by.xpath('//span[@class="mat-option-text"][text()="100"]'))

yong
- 13,357
- 1
- 16
- 27