0

How can I locate an element "1988" (the fourth line) in the following table:

<table border="0" width="820" cellpadding="2" cellspacing="0">
<tbody>
    <tr valign="top">
        <td class="default" width="100%">Results <b>1</b> to <b>10</b> of <b>1988</b></td>
        </tr>
        <tr valign="top">
        <td class="default" bgcolor="#C0C0C0">&nbsp;<font class="resultsheader"> ...etc
        </tr>
    </tbody>
</table>

IMPORTANT: I know one way that works (By.xpath):

driver.findElement(By.xpath("//td[@width='100%']")).getText();

However, this way does not ALWAYS work. The page is dynamic, so I need a way to locate that element no matter what changes happen to the page. I tried the following but I am not sure:

By.xpath("//html//body//table//tbody//tr[3]//td//table//tbody//tr//td[2]//table[4]//tbody//tr[1]//td//b[3]"
4

1 回答 1

2

If you can't change the HTML and want to use attributes for selection, you can write something like this:

//table[@border=0][@width=820]//tbody//tr[1]//td//b[3]
于 2013-03-30T22:58:39.300 回答