1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
package com.itpa.selenium.all_about_webdriver; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class HandlingDemoSiteTable { public static void main(String[] args) throws InterruptedException { WebDriver driver; WebElement o_cell; System.setProperty("webdriver.chrome.driver", "E:\\_Educational\\SeleniumStuff\\SeleniumTrainingPrepStuff\\AT\\Selenium\\ChromeDriver\\chromedriver_win32\\chromedriver.exe"); driver = new ChromeDriver(); driver.get("http://www.itprofessionalacademy.in/demo_site/web_table/index.html"); Thread.sleep(10000); System.out.println("Text is"); //Get row and column count int i_row_count = driver.findElements(By.xpath("//table/tbody/tr")).size(); int i_clm_count = driver.findElements(By.xpath("//table/tbody/tr[2]/td")).size(); for(int i=2;i<=i_row_count;i++){ for(int j=1;j<=i_clm_count;j++){ o_cell = driver.findElement(By.xpath("//table/tbody/tr["+i+"]/td["+j+"]")); System.out.print(o_cell.getText() + ","); } System.out.println(""); } } } |