Indian
Indian

Reputation: 33

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

Upvotes: 3

Views: 88

Answers (2)

Avinash
Avinash

Reputation: 419

Try this (//input[@type="text"])1 this will select the first input field with type text from the page

Use the following link for more examples:

Click for more details

Also yes xpath index starts from 1 not 0.

Upvotes: 0

har07
har07

Reputation: 89285

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]

Upvotes: 3

Related Questions