ladyW
ladyW

Reputation: 13

XPath - find an element based on its parent's sibling's child's text

I have read many online threads and tried many XPath combinations, but it seems that whatever I did, I'm still not able to find my custom XPath for my element. Here is my HTML code, and I need to find the XPath for the highlighted/stared item.

TIA

<div style="display: -moz-box;">
<label for="employeeSel">Select&nbsp;Employees</label>
<table>
    <tbody>
        <tr>
            <td>
                <select id="employeeSel" multiple name="employeeSel" size="10" style="min-width:120px; padding-left:0.4em; padding-right:0.4em">...</select>
            </td>
            <td valign="top">
                **<a onclick="selectAll('employeeSel',true)">Select&nbsp;All</a>**
            </td>
        </tr>
    </tbody>
</table>

xpath issue screenshot

Upvotes: 1

Views: 1113

Answers (1)

zx485
zx485

Reputation: 29022

To select the a element, use the following XPath-1.0 expression:

//div[contains(@style,'display:')]/table/tbody/tr/td[@valign='top'][preceding-sibling::td[select/@id='employeeSel']]/a

A second approach is this:

//div[contains(@style,'display:')]/table/tbody/tr/td[select/@id='employeeSel']/following-sibling::td[@valign='top']/a

Both expression should return the same element a.

Upvotes: 1

Related Questions