2

You knew already we have one of the best useful locators in protractor "element(by.CssContainingText('qwer', 'Apple'))".But I need the same kind of locator in selenium also if we have. I checked in selenium web driver Docs but I didn't find anything. Can you please help with this because I felt it's very easy to find the unique element in HTML by using the above locator.

Thanks in Advance.

1 Answer 1

2

Did you try css with text in following format:

css=div:contains("^ab$") 

It is trying to search a 'div' containing text with 'ab' somewhere in between with regular expression.

Source: A way to match on text using CSS locators

3
  • Thanks for giving the answer.i have small doubt here..can we give any tags like span, form, input, a, instead of div tag ????. Commented Mar 3, 2019 at 16:21
  • 2
    Why don't you try this and come back with what you discovered with all the variations you tried...?This will be helpful for all. Commented Mar 3, 2019 at 20:42
  • I think this Answer is on the right track. You won't be able to search the whole DOM for text in CSS like you might try to do with XPath, but if you have some idea what CSS locator structure it should appear within, it becomes a lot easier.
    – Veretax
    Commented Apr 2, 2019 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.