Selenium-4 || Handling multiple web browsers.

     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

Handling Multiple Web Browsers
Handling Multiple Web Browsers

Understand above image step-by-step:

  1. Write a script to perform an action on any web application. Any programming language can be used.
  2. While programming user can select any web browser.
  3. WebDriver instructs to the specific browser driver like ChromeDriver.exe, FirefoxDriver .exe etc.
  4. 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.
  5. After successful execution of the program result and output will generate.

Selenium Tutorials:

Window Handling: 

Test Frameworks: 

Related Links: 


       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:

  1. Start -> Settings -> About
  2. Get OS Build 16299.461
  3. Navigate to
  4. Search for your OS Build, 16299
  5. 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.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.launchEdge();
	public void launchChrome()
		System.out.println("Launching Chrome Browser...");
		System.setProperty("", "c:\\chromedriver.exe");
		driver=new ChromeDriver();
	public void launchFirefox()
		System.out.println("Launching Firefox Browser...");
		System.setProperty("webdriver.gecko.driver", "c:\\geckodriver.exe");
		driver=new FirefoxDriver();
	public void launchEdge()
		System.out.println("Launching Edge Browser...");
		System.setProperty("webdriver.edge.driver", "c:\\MicrosoftWebDriver.exe");
		driver=new EdgeDriver();
	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);

Leave a Comment

Your email address will not be published. Required fields are marked *

   YouTube ChannelQuora

            Ashok Kumar is working in an IT Company as a QA Consultant. He has started his career as a Test Trainee in manual testing in August 2010. Then he moves towards the automation testing after 4 years. He started learning JAVA and Selenium by self to get the knowledge of automation.

       While learning these tools and working on multiple projects, he found that sometimes people get stuck in live scenarios in their project and they have to do lots of RnD to get out of it. So he decided to start blogging only for such scenarios, where anyone facing any problem in their project, can ask any question or give a solution or you can say an alternate solution to achieve the goal successfully.

Later on, he observed that some people want to learn Java but they have few questions in their mind like how to start Java, whether we should go for the online or offline course. So he started writing tutorials on Java, Jira, Selenium, Excel etc.