1

In a html document I have the following situation:

...
<div data-v-16ed3604="" class="ivu-select ivu-select-single ivu-select-small">
  <div tabindex="0" class="ivu-select-selection xh-highlight">
    <input type="hidden" value=""> 
    <div> 
      <span class="ivu-select-placeholder">Prop</span> 
      ...

<div data-v-16ed3604="" class="ivu-select ivu-select-single ivu-select-small">
  <div tabindex="0" class="ivu-select-selection xh-highlight">
    <input type="hidden" value=""> 
    <div> 
      <span class="ivu-select-placeholder">Something else</span> 
      ...

Here I want to select the first div element with class ivu-select-selection (second row). The XPATH to get the elements with class ivu-select-selection is

//div[@class="ivu-select-selection"]

but it selects two elements. I just want the element which has the span element with the text Prop below it. I want to select just the second row of this html example. .

How to do that?

2 Answers 2

2

Try this,

//span[contains(text(),'Prop')]//ancestor::div[@class='ivu-select-selection xh-highlight']
Sign up to request clarification or add additional context in comments.

6 Comments

But don't I select the element <span class="ivu-select-placeholder">Prop</span> with that expression? That is not what I want. I want to select the SECOND row of my html example...
Can you please share next line of HTML after span , Which you want to target
Could you please mention, what is your second row as according to your example. "I want to select the SECOND row of my html example." I am still not getting, what is your actual target.
Please make sure what you want to target, As according to your question its look like you want to target <span> with text of Prop. Please forget that you can achieve it only through <div> which you have mentioned. Try with the answer you will get desired result for "Prop".
|
1

Try to use below XPath to get required output:

//div[@class="ivu-select-selection" and .//span="Prop"]

Comments

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.