java - 获取表大小时如何排除表的第一行和最后一行

标签 java selenium selenium-webdriver

我有一个带有页眉(1 行)和页脚(1 行)的表格。我得到的表大小和期望值为 50,但它返回 52,因为它同时计算页眉和页脚行。有没有一种方法可以在我的代码中排除页眉和页脚行并获得实际的预期值。这是我获取表格大小的代码

public int getTableSize() throws InterruptedException{
    List<WebElement> columnElements = driver.findElements(By.cssSelector("table[class='table table-bordered table-hover ng-isolate-scope']>tbody>tr"));
  return  columnElements.size();
}

最佳答案

您可以在选择器中使用 :not 来否定第一个子级和最后一个子级

table[class='table table-bordered table-hover ng-isolate-scope']>tbody>tr:not(:first-child):not(:last-child)

关于java - 获取表大小时如何排除表的第一行和最后一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31971478/

相关文章:

java - 请求处理失败;嵌套异常是 org.hibernate.exception.ConstraintViolationException : Could not execute JDBC batch update

java - Jackson 2 和 Spring Autowired bean

java - 调用 WebElement 列表的单个索引

google-chrome - 以编程方式将EnvironmentProperty设置为ChromeDriver

selenium - 在 Selenium 中使用文本单击按钮

java - 使用XmlAdapter在JAXB生成的类中使用java.util.Locale

java - 在其父 shell 的中心生成 swt shell

javascript - Javascript 中的 Selenium - 无法遍历多个站点 : sites. forEach(site => { driver.get(site).sleep(1000).then( do stuff... ) });

google-chrome - WebDriverError : unknown error: Chrome failed to start: exited abnormally

java - 元素尚未准备好被选择,但 wait.until() 仍然继续吗?