"Karmanyevadhikaraste ma phaleshu kadachana, Ma karma phala hetur bhurmatey sangostva akarmani."

Reading the web table contents-rows and column data

public class Web_Tables {

public static void main(String[] args) {
//no.of rows in table

WebDriver driver= new FirefoxDriver();

driver.get("http://www.w3schools.com/tags/tag_table.asp");
WebElement table= driver.findElement(By.xpath("//*[@id='main']/table[2]")); //partial xpath
List<WebElement> rows= table.findElements(By.tagName("tr"));//retrive all rows with tag tr
System.out.println("no.of rows " + rows.size());

for(int rownum=1;rownum<rows.size();rownum++){  //to ignore heading we can ignore first row, so starts from 1
List<WebElement>cells= rows.get(rownum).findElements(By.tagName("td")) ;//corresponding cell content for each row

System.out.println("Total cols is" +cells.size());

//to get the content in all the cells in column

for(int colnum=0;colnum<cells.size();colnum++){
System.out.println(cells.get(colnum).getText() + "---");
}
System.out.println();// to get a new line
}
}

}