Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath for parents sibling

My Html looks like this

 <tr>
    <td>
        <span>
            <img>fieldId:
        </span>
    </td>
    <td>
        <span>
            <input value="false" type="text">
            <input type="hidden" >
        </span>
    </td>
  <td></td>
  <td></td>
</tr>

I want to find the text input field but i know only fieldId which is present under 1st td/span/img I wrote xpath like this

//span[contains(text(),'fieldId')]/../following-sibling::td

But it finds all the td which is present after 1st td so i tried like this

//span[contains(text(),'fieldId')]/../following-sibling::td[0]

But this is not working

Where am i going wrong ??

please help

like image 822
Indian Avatar asked Jan 23 '26 16:01

Indian


1 Answers

XPath index starts from 1, not 0 :

//span[contains(text(),'fieldId')]/../following-sibling::td[1]

Alternatively, you can try this way :

//td[contains(span, 'fieldId')]/following-sibling::td[1]
like image 80
har07 Avatar answered Jan 25 '26 05:01

har07



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!