Sailesh Botcha
Sailesh Botcha

Reputation: 195

How to write XPATH for multiple elements with the same text value with different format in selenium using java

I have one query related to writing XPATH for one scenario as described below.

In Web page lets say we have a text value "Example" which is displayed/ repeated multiple times such as

<div>EXAMPLE</div>
<div>example</div>
<div>ExamPle</div>
<div>ExaMPle</div>
<div>examPLE</div>
<div>eXamplE</div>

Above text value is displayed 10 times in different ways by changing random characters into uppercase or lowercase.

If you observe difference, Value of the text is same but each time different characters are in upper case/lower case.

How can we write a XPATH to get all these elements identified once? Is there a way that we can write an XPATH to fetch all this elements once?

Thanks in advance.

Upvotes: 0

Views: 441

Answers (1)

Prophet
Prophet

Reputation: 33371

You can use this:

/html/body//text()[
  contains(
    translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),
    'example'
  )
]

For more explanations see here

Upvotes: 4

Related Questions