Open Browser in Selenium

Opening a browser with binary File:

There will be situations, where you have to test your web application against two different versions of the  browser.

For example consider FireFox, By default, when you create object to FirefoxDriver, the Firefox version that is available on the PATH variable is launched.

But if you want to launch a different version of Firefox, we need to use Firefox Binary, or if the browser is not in the standard PATH then you should specify the browser binary file location to open the browser.

public static void main(String[] args) {
	File pathToBinary = new File("C:\\PATH\\App\\Firefox\\firefox.exe");
	FirefoxBinary firefoxBinary = new FirefoxBinary(pathToBinary);
	FirefoxProfile firefoxProfile = new FirefoxProfile();      
	WebDriver driver = new FirefoxDriver(firefoxBinary,firefoxProfile);


Launch Internet Explorer :

Webdriver is an Interface and InternetExplorerDriver() is a class which has implemented Webdriver Interface.

You should invoke the InternetExplorerDriver() constructor to open the internet explorer browser in selenium.

To execute test script on Internet Explorer, you need to download an external .exe file IEDriverServer, a standalone server to execute test scripts on Internet Explorer.

User can download the server from and keep it in a desired location.

Set the system’s property to point to the location where the IEDriverServer file is kept.

Setting system property is nothing but setting environment variables for the JVM, once the JVM exits these properties will be destroyed.

Choose IEdriverserver based on your work environment because there are two separate zip files for both 32 and 64 bit IE.

public static void main(String[] args) {
      // Set path for Internet Explorer server executable
       System.setProperty("", "C:\\PATH\\IEDriverServer.exe");
       // Launch IE browser
      WebDriver  driver = new InternetExplorerDriver();
      // open the google
       // close the browser

Few Observation From IE with Selenium:

  • The IE browser is slower than other browsers, slower than edge
  • IE browser zooming level must be set to 100% otherwise, you will get an exception.
  • You must also check your security settings in IE when you turn on the IE browser in the Selenium, all your areas should be enabled or disabled.
  • IE will have failures because of xpath, so try to avoid xpath and use css selector


Firefox Browser with Selenium:

Webdriver is an Interface and FirefoxDriver() is a constructor of FirefoxDriver class which has implemented Webdriver Interface.


A proxy for W3C WebDriver-compatible clients to interact with Gecko-based browsers. Geckodriver provides the HTTP API described by the WebDriver protocol, so that Gecko browsers, such as Firefox.

Mozilla runs on Gecko browser engine and Gecko browser engine is developed by Mozilla.

Ttill firefox 47, selenium has provided inbuilt support for selenium but Firefox 48 onward Firefox has started using gecko engine, so selenium was not able to support it by default.

If you trying to open a Firefox version newer than 47, then you must use Gecko driver to open Firefox.

You can download the latest executable on the GitHub page (  and make sure to download the correct driver file based on your platform and OS version.

After Downloading set the environment variable using setProperty() method in selenium

public static void main(String[] args) {
       // Set geckodriver path
       // Open browser
       WebDriver driver = new FirefoxDriver();
       // open google
       // close firefox browser

Open Google Chrome with Selenium :

Like Internet Explorer, Google Chrome also requires user to download an external utility ChromeDriver, a standalone server to execute test scripts on Google Chrome.

User can download the ChromeDriver file from The rest of the process would remain the same as that of Internet Explorer.

public static void main(String[] args) {
       // Set path for Chrome Driver executable path
       System.setProperty("", "C:/lib/chromedriver.exe");
       // Launch ChromeDriver
       WebDriver driver = new ChromeDriver();
       // Open the web page
        // close the browser


Open Safari Browser with Selenium:

SafariDriver comes along with the Selenium server’s package, so user is not required to download or set any external entity. It is readily available to execute the test scripts on Safari.

public static void main(String[] args){
       // Launch SafariDriver
       WebDriver driver = new SafariDriver();
       // Open the web page
       // close the browser and quite the driver

Leave a Reply

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