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

Selenium webdriver 如何使用SeleniumWebDriver从表中获取最后一行数据,selenium-webdriver,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

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

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("");

 }
WebElement webtable=driver.findElement(By.id(“requisitionsTable”);
List rowCollection=webtable.findElements(By.xpath(“/*[@id='requisitionsTable']/tbody/tr”);
System.out.println(“WebTable中的行数:”+rowCollection.size());
for(WebElement行元素:行集合)
{
System.out.println(“rowElement”+rowElement.getText());
List colCollection=rowElement.findElements(By.xpath(“td”);
for(WebElement colElement:colcolcollection)
{
System.out.print(colElement.getText());
系统输出打印(“”);
} 
System.out.println(“”);
}

使用下面的CSS选择器获取最后一行数据

By lastRow=By.cssSelector("table#requisitionsTable tr:last-child");

driver.findElement(lastRow).getText();

嗨,Santosh,我尝试了上面的代码,但得到了错误“定位器未找到”,所以我尝试了int rowSize=rowCollection.size();系统输出打印项次(行大小);按lastRow=By.xpath(“/*[@id='requisitionsTable']/tbody/tr[“+rowSize+”]);System.out.println(“最后一行”+driver.findElement(最后一行).getText());还有一个问题是我们正在使用分页,所以它只获取第一页的最后一行,而不是进入第二页。欢迎。但是,在获取第一页的最后一行数据时,上述逻辑应该可以正常工作;或int rowSize=rowCollection.size();By lastRow=By.cssSelector(“表#requisitionsTable tr:rowSize”);但后来也没有得到