0

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

1 Answer 1

1

Here is the xpath.

//span[normalize-space(.)='element2']/parent::div/i[normalize-space(.)='close']

Just change the element that you want.

Sign up to request clarification or add additional context in comments.

2 Comments

lol, that works... thank you so much! I'd like to understand why are you using normalize-space(.) or what does mean? :)
just to make sure to ignore any spaces before and after the text. Just a simple trim.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.