WebDriver获得表格里所有单元格的文本
                 jopen
                 12年前
            
                    方法为:
1. 得到表格中所有的tr,存到list到中
2.对tr进行循环,根据当前的tr,得到当前所有td的集合存到list当中
3.循环中所有td里的文本
具体实现为
    package com.example.tests;        import static org.junit.Assert.*;        import java.util.*;        import org.junit.*;        import org.openqa.selenium.*;        import org.openqa.selenium.ie.InternetExplorerDriver;        public class Selenium2 {            WebDriver driver = new InternetExplorerDriver();            JavascriptExecutor jse = (JavascriptExecutor)driver;            @Test            public void tableTest() {                   driver.get("http://www.w3school.com.cn/html/html_tables.asp");                   //首先得到所有tr的集合                List<WebElement> rows = driver.findElements(By.cssSelector(".dataintable tr"));                 //验证表格的行数                assertEquals(11,rows.size());                 //打印出所有单元格的数据                for (WebElement row : rows) {                     //得到当前tr里td的集合                    List<WebElement> cols =  row.findElements(By.tagName("td"));                     for (WebElement col : cols) {                        System.out.print(col.getText());//得到td里的文本                    }                    System.out.println();                }                driver.close();            }        }  打印结果为  ---------------------------------------------------------------------------------
<table>定义表格
  <caption>定义表格标题。
  <th>定义表格的表头。
  <tr>定义表格的行。
  <td>定义表格单元。
  <thead>定义表格的页眉。
  <tbody>定义表格的主体。
  <tfoot>定义表格的页脚。
  <col>定义用于表格列的属性。
  <colgroup>定义表格列的组。