Display complete data of the table using selenium webdriver

package tableAutomation;

import org.testng.annotations.Test;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;

public class DispayAllTableData {
    WebDriver driver;
    @Test
    public void DisplayFullTable() throws Exception {

        driver.get("http://www.seleniumlearn.com/table");
        driver.manage().timeouts().implicitlyWait(19, TimeUnit.SECONDS);
        Thread.sleep(3000);    

        WebElement table=driver.findElement(By.xpath("//table"));
        List<WebElement> rows    = table.findElements(By.xpath("//tr"));
        List<WebElement> columns = table.findElements(By.xpath("//th"));

        System.out.println("Number of rows:"+rows.size());
        System.out.println("Number of columns:"+columns.size());
        System.out.println("=============Full Table Data================="); 
        for(int td=0;td<rows.size();td++)
        {
            System.out.println(rows.get(td).getText());
        }
    }
    @BeforeTest
    public void beforeTest() {
        driver=new FirefoxDriver();
        //System.setProperty("webdriver.chrome.driver","D:\\lib\\chromedriver.exe"); //---> Chromedriver path
        //driver = new ChromeDriver();
    }

}

Comments