【问题标题】:Selenium - Skip a tableSelenium - 跳过一张桌子
【发布时间】:2016-05-07 04:13:20
【问题描述】:

我正在尝试使用 Selenium 从表中提取一些数据。我试图从中提取数据的页面在页面上有 2 个单独的表,我需要的数据在第二个表中。我已经使用它的 ID 指向了第二个表,但我不断从第一个表中取回数据。这是我用来从表中提取的代码。

WebElement table = driver.findElement(By.id("tblSBResults"));
    String date = table.findElement(By.xpath("//tbody/tr[1]/td[1]")).getText();

我也尝试过将 xpath 设为 //table/tbody/tr[1]/td[1]。

这就是我要从中提取的表格的样子。

<table>
    <tbody>
        <tr>
            <td>some data</td>
            <td>more data</td?
        </tr>
    </tbody>
</table>
...
...
<table id  = "tblSBResults">
    <tbody>
        <tr>
            <td>6/9/2015</td>
            <td>More data that I need</td>
            <td>more needed data</td>
        </tr>
        <tr>
            <td>more etc</td>
            <td>I think you get the point</td>
        </tr>
    </tbody>
</table>

任何想法将不胜感激。顺便说一句,我正在使用 Selenium 的 Java 版本。 谢谢!

【问题讨论】:

    标签: java html selenium selenium-webdriver


    【解决方案1】:

    使用 // 将在页面顶部开始搜索。

    试试这个:

    WebElement table = driver.findElement(By.id("tblSBResults"));
    String date = table.findElement(By.xpath("tbody/tr[1]/td[1]")).getText();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-24
      • 2012-05-23
      • 1970-01-01
      • 2021-11-19
      • 2017-02-07
      • 2011-11-17
      • 2011-10-09
      • 2020-07-29
      相关资源
      最近更新 更多