Posts

Showing posts from 2017

How To Handle Dynamic Web Table In Selenium WebDriver

Image
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



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.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class DynamicTable { WebDriver driver = new FirefoxDriver(); @BeforeTest public void setup() throws Exception { driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("http://only-testing-blog.blogspot.in/2014/05/form.html"); } …

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

Image
Following Script will extract table data:

import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class table { WebDriver driver = new FirefoxDriver(); @BeforeTest public void setup() throws Exception { driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.get("http://only-testing-blog.blogspot.in/2013/09/test.html"); } @AfterTest public void tearDown() throws Exception { driver.quit(); } @Test public void print_data(){ //Get number of rows In table. int Row_count = driver.findElements(By.xpath("//*[@id='post-body-6522850981930750493']/div[1]/table/tbody/tr")).size(); System.out.println("Number Of Rows = &q…

Handling 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.








import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Switchbetweenbrowsertab { public static void main(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("bod…