user1935987
user1935987

Reputation: 3347

xpath select child element changing depth dynamically

This is html source i have:

<td class="Ap">
    <div>
        <div><textarea></textarea></div>
    </div>
    <div>
        <div attribute="true">
            <div><img src="blabla" width="412" height="309"></img></div>
        </div>
    </div>
</td>

How can i get the child <img> element based in <div attribute="true"> if the <img> changing it's depth like it can be for example:

<td class="Ap">
    <div>
        <div><textarea></textarea></div>
    </div>
    <div>
        <div attribute="true">
          <div>
           <div>
            <div><img src="blabla" width="412" height="309"></img></div>
           <div>
          <div>
        </div>
    </div>
</td>

Upvotes: 0

Views: 227

Answers (1)

Phil Blackburn
Phil Blackburn

Reputation: 1067

Here are a few options for you:

//img[ancestor::div/@attribute='true']

or

//div[@attribute='true']//img

or

//div[@attribute='true']/descendant::img

All of these will find all the img nodes contained below the div

Upvotes: 1

Related Questions