How to get Text() value of XPath

I'm trying to get a text() value of a someValue in a table.

This is the html:

<div class="giveHeight">
<table width="100%" cellspacing="0" cellpadding="3" border="0" id="loads" class="dataTable" aria-describedby="loads_info">
    <thead>
        <tr class="tableHeading" role="row">
            ...Header...
        </tr>
    </thead>                    
    <tbody role="alert" aria-live="polite" aria-relevant="all">
        <tr class="odd">
            <td class=" ">SomeValueInTheFirtColumn</td>
            <td style="text-align: center;" class=" ">1</td>
            <td class=" ">aabbcc</td>
            <td class=" ">CityA</td>
            <td class=" ">AA</td>
            <td class=" ">CityB</td>
            <td class=" ">BB</td>
            <td style="text-align: right;" class=" ">00</td>
            <td style="text-align: right;" class=" ">$1.00</td>
            <td style="text-align: right;" class=" ">$1.00</td>
            <td style="text-align: right;" class=" ">
                <a href="/xx/xx.asp?id=99999">
                    <img src="/tab/images/icons/view.gif" border="0" alt="view" width="14" height="14">
                </a>
            </td>
            <td style="text-align: right;" class=" "></td>
        </tr>
    </tbody>
</table>

In the first column, there is a value that I want to find. However, it depends on a part of values in of cityA and cityB.

I was trying something like that but is not working:

//div[@class='giveHeight']/table/tbody/tr/td/td[following-sibling::td[text()='CityA']/following-sibling::td[text()='CityB']]/text()

Upvotes: 0

Views: 165

Answers (1)

zx485
zx485

Reputation: 29022

I'm not sure that this is what you want, but to get the value SomeValueInTheFirtColumn, you only have one td too many in your XPath. So change it to

//div[@class='giveHeight']/table/tbody/tr/td[following-sibling::td[text()='CityA']/following-sibling::td[text()='CityB']]/text()

and you get SomeValueInTheFirtColumn as the result.

But the following, shorter, expression does achieve the same result:

//div[@class='giveHeight']/table/tbody/tr/td[1]/text()

On the other hand, if you like to retrieve the value 'AA' between CityA and CityB, the following XPath will extract what you want:

//div[@class='giveHeight']/table/tbody/tr/td[following-sibling::td[text()='CityB'] and preceding-sibling::td[text()='CityA']]/text()

Upvotes: 1

Related Questions