如何使用selenium webdriver从表中获取最后一行数据

时间:2015-06-23 06:49:18

标签: selenium-webdriver

我使用下面的代码来获取表中的所有行,但我只想要最后一行数据

WebElement webtable=driver.findElement(By.id("requisitionsTable")); 

List <WebElement> rowCollection=webtable.findElements(By.xpath("//*[@id='requisitionsTable']/tbody/tr"));
System.out.println("No. of Rows in the WebTable: "+rowCollection.size());


for(WebElement rowElement:rowCollection)
{
    System.out.println("rowElement"+rowElement.getText());
      List<WebElement> colCollection=rowElement.findElements(By.xpath("td"));

      for(WebElement colElement:colCollection)
      {
           System.out.print(colElement.getText());
           System.out.print(" ");

       } 
      System.out.println("");

 }

1 个答案:

答案 0 :(得分:0)

使用下面的cssSelector获取最后一行数据。

app.get('/:trial', function(req, res){
    var trial = req.params.trial;
    trial.find(function(err, records) {
        if (err)
            res.send(err);

        res.json(records); // returns all trial records in JSON format
    });
});