假设这个table的id为“table” 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public void clickName(String name){ //获取table的总行数 //如果/table/tbody中的tr有class属性为"tr",且在tbody之外没有控件的class属性是这个 int rowNum = driver.findElements(By.className("tr")).size(); //如果没有上面那个条件,则使用tagName获取tbody内的行数 int rowNum = driver.findElement(By.xpath("//table[@