i
WebDriver Introduction
Selenium WebDriver Architecture
Introduction to WebDriver API
Introduction to WebDriver – Code
Handling Dropdowns and Select class
Handling Multiple Dropdown values and Links
Handling Radio buttons and Checkboxes
Capture Screenshots and Email test results
Browser Navigation Methods
Handling tabs
Capturing screenshot, Handling tabs and pop-ups – Code
Handling tabs and Pop-ups – Code
Handling Alerts
Handling User Authentication and Input alerts
HtmlUnitDriver and Handling Captchas
Handling Web Tables
Synchronization
Handling WebTables, Synchronization issues, Firefoxprofiles – Code
Actions Class
Event Listeners, Event Firing Mouse, Coordinates – Code
Handling Mouse Hover in Selenium
JavascriptExecutor
Handling Iframes
IsElementPresent, IsEnabled, IsSelected
Working with Chrome Driver - Part 1
Working with FireFox Driver - Part 2
Working with Internet Explorer Driver - Part 3
Handling SSL Certificate
Desired Capabilities
How to Encode password in WebDriver
Handling JQuery Elements - Drag and Drop, Sliders, Resizable
Handling JQuery Elements - Drag and Drop, Sliders, Resizable – Code
Working on IE Browser using Actions
TestNG, Ant & Report Generation through XSLT
Introduction to TestNG and Annotations
TestNG Parameterization
Configuring ANT, Generating TestNG & XSLT Reports
Code for generating XSLT / Surefire Reports through MAVEN
TestNG Parameterization Excel Reading
Handling Multiple data providers
TestNG XSLT Jar, Build.xml & TestNG.xml file
Frameworks Introduction
Hybrid (DATA + KEYWORD) driven Framework
Framework Architecture
Reading Excel sheets
TestNG DataProvider
Data Provider with Hashtable
Handling Multiple Test Suites
Multiple DataProviders
Setting up Run-modes at Suite Level
Setting up Runmodes at TestCase Level
Creating a common utility for Run-modes
Hybrid Framework Code
As we discussed that we have various ways to handle the synchronization problems in Selenium automation. Let us see how to implement the same in Selenium scripts one by one:
Wait without condition:
As we are aware of using the Thread class to call the sleep() method and pass some milliseconds value as parameter to stop threads for a specific time. Let us see the small sample code to use this wait in a Selenium script.
package SeleniumTest.SeleniumTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ThreadWait
{
public static void main( String[] args ) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://selflearning.io/");
Thread.sleep(5000);
WebElement element=driver.findElement(By.xpath("/html/body/section[1]/div/div/section/div[1]/div[2]/ul/li[2]/a"));
}
}
The implicit wait is declared before launching the web page URL, and then it remains for the entire session of the driver object. Let us see how to utilize this wait in our Selenium scripts.
package SeleniumTest.SeleniumTest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class WaitSelenium
{
public static void main( String[] args )
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://selflearning.io/");
}
}
As we have already discussed that Explicit wait is a wait which is set with a condition and a timeout time. This checks for the condition with a polling frequency during the entire timeout. Let us see the complete sample code to implement this wait in the Selenium script.
package SeleniumTest.SeleniumTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ExplicitWait
{
public static void main( String[] args )
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://selflearning.io/");
WebDriverWait wait=new WebDriverWait(driver,10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='popular-it-skill']/div[5]/a")));
}
}
We discussed detail about Fluent wait that it gives the option to define the maximum wait time and the polling time in which the WebDriver checks for the condition. This gives an option to set any specific exception to ignore during the polling. Let us see how to define a fluent wait in a Selenium script:
package SeleniumTest.SeleniumTest;
import java.util.NoSuchElementException;
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.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import com.google.common.base.Function;
public class FluentWaitSelenium
{
public static void main( String[] args )
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\AC42610\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://selflearning.io/");
@SuppressWarnings("deprecation")
Wait<WebDriver> wait=new FluentWait<WebDriver>(driver)
.withTimeout(20, TimeUnit.SECONDS)
.pollingEvery(250, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
WebElement element=wait.until(new Function<WebDriver,WebElement>()
{
public WebElement apply(WebDriver driver)
{
return driver.findElement(By.xpath("//*[@id='popular-it-skill']/div[5]/a"));
}
});
}
}
Firefox Profile:
As we have created a Firefox profile in the previous topic and now, we need to see how to use the same in our Selenium script. We can use the “ProfilesIni” class to set the Firefox profile with the Firefox driver object.
package SeleniumTest.SeleniumTest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class FirefoxProfileCreation
{
public static void main( String[] args )
{
ProfilesIni profile = new ProfilesIni();
FirefoxProfile fp = profile.getProfile("SelflearningSeleniumTest");
FirefoxOptions opt = new FirefoxOptions();
opt.setCapability(FirefoxDriver.PROFILE, fp);
WebDriver driver = new FirefoxDriver();
driver.get("https://selflearning.io/");
}
}
Don't miss out!