Rich Stevens
Rich Stevens

Reputation: 609

XPATH use multiple AND statments with CONTAINS or STARTS WITH

<tr>
                <td>Principal</td>
                <td class="xh-highlight">Brian Jones</td>
            </tr>

I am using the following to return a td that contains the word 'princpal':

//td[starts-with(., "Princ")]/following-sibling::td
//td[contains(., 'Princ')]/following-sibling::td

Both work fine, but some of the html pages I am looping through use different terminology so I need to look for different terms. Example, some use 'headmaster' or even just 'head':

<tr>
                    <td>Headmaster</td>
                    <td class="xh-highlight">Mrs Baines</td>
                </tr>

What I need to do is use some kind of OR statement, I have been playing with variations of this:

//td[contains(., 'Princ' and contains ., 'head' and contains 'chief')]/following-sibling::td

As I need a few tests to find the right one. I cannot get this to return any results.

Upvotes: 2

Views: 1088

Answers (1)

Andersson
Andersson

Reputation: 52665

Try below expression:

//td[contains(., 'Princ') or contains(., 'Head') or contains(., 'Chief')]/following-sibling::td

or

//td[matches(., ("Princ|Head|Chief"), "i")]/following-sibling::td

if your tool supports matches()

Upvotes: 4

Related Questions