2015-02-19 4 views
0

Я пробовал с кодировкой ниже, чтобы получить текст из таблицы. Он работает отлично. Но я хочу выбрать данные только из первого столбца. Как я могу захватить текст из первого столбца. ,Как получить текст из первого столбца таблицы?

WebElement tableContents = pubDriver.findElements(By.id("view_table")); 

    List<WebElement> rows=tableContents.findElements(By.tagName("tr")); 
    for(int rnum=0;rnum<rows.size();rnum++) 
    { 
    List<WebElement> columns=rows.get(rnum).findElements(By.tagName("td")); 

    for(int cnum=0;cnum<columns.size();cnum++) 
    { 
    System.out.println(columns.get(cnum).getText()); 
    } 
    } 

Я попытался с ниже кодирования, я не получил текст из первой колонки

columns.get(0).getText(); 

ответ

1

вы можете сделать, как это ....

// Create a new instance of the html unit driver 
// Notice that the remainder of the code relies on the interface, 
// not the implementation. 
WebDriver driver = new FirefoxDriver(); 

// And now use this to visit Google 
driver.get("http://localhost:8081/TestXmlDisplay/tabletest.html"); 

WebElement tableContents = driver.findElement(By.tagName("table")); 

List<WebElement> rows=tableContents.findElements(By.tagName("tr")); 
for(int rnum=0;rnum<rows.size();rnum++) 
{ 
List<WebElement> columns=rows.get(rnum).findElements(By.tagName("td")); 


System.out.println(columns.get(0).getText()); 

} 

// драйвер .уволиться();