As we all know, that using the Selenium web drivers user can handle multiple web browsers to execute test cases on different browsers. This helps us to execute the same set of script for any application on cross-browser platforms.
Multiple Web Browsers

Understand above image step-by-step:
- Write a script to perform an action on any web application. Any programming language can be used.
- While programming user can select any web browser.
- WebDriver instructs to the specific browser driver like ChromeDriver.exe, FirefoxDriver .exe etc.
- Now, these third party exe drivers handle the web browsers. It gives instructions to the browsers to perform an action based on the automation script.
- After successful execution of the program result and output will generate.
Selenium Tutorials:
- Selenium-1 || Understanding Selenium and Selenium WebDriver.
- Selenium-2 || Let’s learn Selenium IDE.
- Selenium-3 || First program using Selenium Web Driver.
- Selenium-4 || Handling multiple web browsers.
- Selenium-5 || Locating web elements using various type of Locators.
- Selenium-6 || XPath is the best way to locate web elements.
- Selenium-7 || Let’s learn to create complex XPath.
- Selenium-8 || Implementing Wait(s) in Selenium.
- Selenium-9 || Understanding WebDriver API.
- Selenium-10 || Taking Screenshots using Selenium
- Selenium-11 || Use of Actions and Action Classes.
- Selenium-12 || Select Class to handle drop-down.
- Windows Handling | Multiple windows handling using JavascriptExecutor.
- iFrame || Multiple ways to handle iFrame html tag using selenium.
- iFrame || iFrame Handling within a web page.
- getWindowHandle() and getWindowHandles() methods.
- Properties File | Accessing properties file for user input or test data.
- Framework || Simple example of Key Driven Framework using excel sheet in Selenium(JAVA).
- TestNG – 16 || Access data from Excel sheet using DataProvider.
- Selenium Grid | Configuration and implementation with Example.
- TestNG – 1 || Introduction and benefits of TestNG Framework.
- TestNG – 2 || Installation process and a sample program of TestNG.
- TestNG – 3 || Create and execute multiple Test Cases.
- TestNG – 4 || Let’s understand @Test Annotation and attributes.
- TestNG – 5 || Understand Assertion in TestNG.
- TestNG – 6 || Use of @BeforeMethod and @AfterMethod.
- TestNG – 7 || Use of @BeforeClass and @AfterClass.
- TestNG – 8 || Creation and execution of Test Suites.
- TestNG – 9 || Let’s move deep into the Test Suites.
- TestNG – 10 || Use @BeforeTest and @AfterTest Annotations.
- TestNG – 11 || Groups attribute with @Test Annotation.
- TestNG – 12 || Use of @BeforeGroups & @AfterGroups.
- TestNG – 13 || Use of @BeforeSuite & @AfterSuite.
- TestNG – 14 || DataProvider annotation & attribute.
- TestNG – 15 || DataProvider with parameters.
- TestNG – 16 || Access data from Excel sheet using DataProvider.
- TestNG – 17 || Passing multiple Parameters in testng xml.
- TestNG – 18 || Multiple Browser and Parallel Execution in TestNG.
- TestNG -19 || Concept of Parallel Execution.
- TestNG – 20 || Run TestNG Program using main() method.
- Headless Testing via ChormeOptions Class.
Note:
Although, the basic code to handle web browsers remains same. Still, for each type of web browser, the configuration may differ. In the below example we have taken most used browsers like Chrome, Firefox, Edge, Opera etc.
For Edge browser, we have to download a specific MicrosoftWebDriver.exe file, depending on the Windows 10 build version. To get the correct version of build follow below steps:
- Start -> Settings -> About
- Get OS Build 16299.461
- Navigate to https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
- Search for your OS Build, 16299
- Download specific version of the driver.
For Opera browser, we have to set the binary path of Opera using setBinary and DesiredCapabilities keywords. Let’s start with the coding.
Code Example:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.opera.OperaDriver; import org.openqa.selenium.opera.OperaOptions; import org.openqa.selenium.remote.DesiredCapabilities; public class Test { // Class level variable of WebDriver. WebDriver driver; public static void main(String[] args) { // Creating object of Test Class. Test obj=new Test(); // Calling specific method to launch different browsers. //obj.launchChrome(); //obj.launchFirefox(); // obj.launchEdge(); obj.launchOpera(); } public void launchChrome() { System.out.println("Launching Chrome Browser..."); System.setProperty("webdriver.chrome.driver", "c:\\chromedriver.exe"); driver=new ChromeDriver(); driver.get("http://www.allinoneblogs.com"); } public void launchFirefox() { System.out.println("Launching Firefox Browser..."); System.setProperty("webdriver.gecko.driver", "c:\\geckodriver.exe"); driver=new FirefoxDriver(); driver.get("http://www.allinoneblogs.com"); } public void launchEdge() { System.out.println("Launching Edge Browser..."); System.setProperty("webdriver.edge.driver", "c:\\MicrosoftWebDriver.exe"); driver=new EdgeDriver(); driver.get("http://www.allinoneblogs.com"); } public void launchOpera() { System.out.println("Launching Opera Browser..."); System.setProperty("webdriver.opera.driver", "c:\\operadriver.exe"); ChromeOptions options=new ChromeOptions(); options.setBinary("C:\\Program Files\\Opera\\launcher.exe"); DesiredCapabilities cap=DesiredCapabilities.opera(); cap.setCapability(ChromeOptions.CAPABILITY, options); driver=new OperaDriver(cap); driver.get("http://www.allinoneblogs.com"); } }