Posts

Showing posts from February, 2017

How To Handle Dynamic Web Table In Selenium WebDriver

In this selenium webdriver post, we will learn how to handle dynamic web table. There might occur some scenarios where every time a page loads with different number of rows and columns or different columns for each row.

For that, we have to put two for loops,
1. first loop will iterate all the rows and
2. second loop inside it will iterate the columns of each row



publicclassDynamicTable{ WebDriver driver =new FirefoxDriver();@BeforeTestpublicvoidsetup()throws Exception { driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://www.techlistic.com/p/sample-table.html");}@AfterTestpublicvoidtearDown()throws Exception { driver.quit();}@Testpublicvoidtest_Dynamic_Webtable(){// Locate table WebElement mytable = driver.findElement(By.xpath(".//*[@id='post']/div[1]/table/tbody"));// Locate rows of table and save locators of each row in a list List rows_table = mytable.findElements(By.…

How To Extract Table Data/Read Table Data Using Selenium WebDriver

Image
Following Script will extract data from table:


publicclasstable{ WebDriver driver =new FirefoxDriver();@BeforeTestpublicvoidsetup()throws Exception { driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.get("https://www.techlistic.com/p/sample-table.html");}@AfterTestpublicvoidtearDown()throws Exception { driver.quit();}@Testpublicvoidprint_data(){//Get number of rows In table.int Row_count = driver.findElements(By.xpath("//*[@id='post']/div[1]/table/tbody/tr")).size(); System.out.println("Number Of Rows = "+Row_count);//Get number of columns In table.int Col_count = driver.findElements(By.xpath("//*[@id='post']/div[1]/table/tbody/tr[1]/td")).size(); System.out.println("Number Of Columns = "+Col_count);//divided xpath In three parts to pass Row_count and Col_count values. String first_part ="//*[@id='post']/div[1]/table/tbody/tr["; S…

How to Handle Multiple Browser Tabs Using Selenium Webdriver?

Image
We can perform a number of actions by combining third party things along with Webdriver, which webdriver is not capable if doing it alone. In this context sharing with you a program of handling multiple tabs. We can make use of Key controls which Robot api of java provides, to handle multiple tabs.








publicclassSwitchBetweenBrowserTab{publicstaticvoidmain(String[] a)throws InterruptedException {// Initialize driver WebDriver driver =new FirefoxDriver();//Maximize browser window driver.manage().window().maximize();//Go to URL driver.get("http://www.google.com");//Set timeout driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);// Open new tab driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL+"t");//Go to URL driver.get("http://www.gmail.com");//Set new tab timeout driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);// Do some operation driver.…