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);

5062total visits,4visits today

Leave a Reply

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