Zelo
Zelo

Reputation: 332

How to get values in similar but little bit different nodes with xpath in one query?

I want to create xpath query to get url from link1 and link 2 with requirement to not change the order in results.

First situation
<div id="id">
    <span class="class">
        <a href=http://whatever.url>link 1</a>
    </span>
</div>
Second Situation
<div id="id">
    <span class="class anotherclass">
        <h5>
            <a href=http://whatever.url>link 2</a>
        </h5>
    </span>
</div>
(...Above situation can happen more times on site in any order...)

The problem in my case is as i shown in code that nodes are similar but sometimes can have an extra parent element (in this example h5 tag) to link. One of my ideas was to get the same part of each node and than make something like this:

 (pseudo code)
div:id:id/span:class:class/(h5/a/@href or a/@href)

But i can't get it working.

Upvotes: 1

Views: 61

Answers (1)

Simon Mourier
Simon Mourier

Reputation: 139256

What about something like this, using // on the "variable" hierarchy

div[@id='id']/span[@class]//a[@href]

Upvotes: 2

Related Questions