Reputation: 13
This is the example
<div>
<div _ngcontent-c20="" class="element">
<span _ngcontent-c20="" class="chip-name tv-h-no-select"> element1 </span><!---->
<i _ngcontent-c20="" aria-hidden="true" class="close"><!---->close<!----></i></div>
<div _ngcontent-c20="" class="element">
<span _ngcontent-c20="" class="chip-name tv-h-no-select"> element2 </span><!---->
<i _ngcontent-c20="" aria-hidden="true" class="close"><!---->close<!----></i></div>
<div _ngcontent-c20="" class="element">
<span _ngcontent-c20="" class="chip-name tv-h-no-select"> element3 </span><!---->
<i _ngcontent-c20="" aria-hidden="true" class="close"><!---->close<!----></i></div>
<div _ngcontent-c20="" class="element">
<span _ngcontent-c20="" class="chip-name tv-h-no-select"> element4 </span><!---->
<i _ngcontent-c20="" aria-hidden="true" class="close"><!---->close<!----></i></div>
</div>
Here is the thing,
I want to create an xpath that press the "CLOSE" button but depending on which element I want to close...
we have 4 elements, but I just want to press the close button for the element that I want
I would like to create an xpath with Axes in order to pick the element that I want:
this is my current xpath:
//div//span[contains(text(), 'element1')]
but with this xpath is just clicking the element1 and not the "close" button.
now I would like to create an xpath choosing the element with Axes and identifying the "close" button to be pressed
Upvotes: 0
Views: 32
Reputation: 14145
Here is the xpath.
//span[normalize-space(.)='element2']/parent::div/i[normalize-space(.)='close']
Just change the element that you want.
Upvotes: 1