Diesel Kumar Diesel Kumar - 2 months ago 16
CSS Question

How to find xpaths of depth tags of an div element?

<div class="buttonContainer">
<label for="btn_123456">
<span>
<img style="visibility:hidden;">
Text1
</span>
</label>
</div>
<div class="buttonContainer">
<div class="buttonContainer">
<div class="buttonContainer">


To locate the elements for each div element goes like this,
//div[@class='buttonContainer'][1] , //div[@class='buttonContainer'][2]
and so on.

Text content varies for each div element, under img tag.
How to locate the elements based on it's text content (optimized)?

Answer:
//span[contains(text(),'Text1')]
Irrespective of div elements.

Answer Source

try with the xpath like //div[@class='buttonContainer']/label/span[contains(text(),'Text1']