Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
December 11, 2016

Launch Browser in Selenium3





How to Launch Browser in Selenium 3 will discuss about how to open different kind of browsers (i.e. Firefox,Chrome,Opera and Edge etc…) using selenium webdriver version 3 and automate the applications. In previous versions of selenium, firefox has different kind of approach to launch and remaining browsers had another kind of approach. But in the latest version of selenium (i.e. Selenium Webdriver 3), all the browsers will be launched almost same way.

In this blog will see how to launch the browsers in Mac and Windows as both have little bit of difference while writing the code for launching the browser.

Mac Machine:

Launch FirefoxBrowser:

To launch firefox browser in selenium 3 we need to download the latest “Mozilla Gecko Driver” and unzip the same and place in “/usr/local/bin” folder. And write the below sample code to launch firefox and navigate to a particular URL.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class LaunchFirefox
{
    public static void main(String[] args) 
    {
       WebDriver driver = new FirefoxDriver();
       // This Site is useful to practice basic Selenium
       driver.get("http://demo.automationtesting.in");
       driver.quit();
    }
}

Launch ChromeBrowser:

To launch chrome browser in selenium 3 we need to download the latest “Chrome Driver” and unzip the same and place in “/usr/local/bin” folder. And write the below sample code to launch chrome and navigate to a particular URL.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class LaunchChrome
{
    public static void main(String[] args) 
    {
        WebDriver driver = new ChromeDriver();
        // This Site is useful to practice basic Selenium
        driver.get("http://demo.automationtesting.in");
        driver.quit();
    }
}

Launch SafariBrowser:

Launching Safari browser in Selenium 3 is bit different from chrome and firefox as Safari is giving provision to launch the browser in different way. For, this we do not need to download any files. Instead, need to do some configuration in the safari browser. Below are the steps to perform before writing the selenium code:

  1. We need to enable the Develop menu in the Safari browser. For this need to go to Safari > Preferences. Then go to Advanced tab then check the “Show Develop menu in menu bar” checkbox.
  2. Tick the “Allow Remote Automation” in Develop menu.

And write the below sample code to launch safari and navigate to a particular URL.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.safari.SafariDriver;

public class LaunchSafari
{
    public static void main(String[] args) 
    {
        WebDriver driver = new SafariDriver();
        // This is Site useful to practice basic Selenium
        driver.get("http://demo.automationtesting.in");
        driver.quit();
    }
}

These are the ways to launch the different types of browsers in Mac Machine.



Windows Machine:

Launch FirefoxBrowser:

To launch firefox browser in selenium 3 we need to download the latest “Mozilla Gecko Driver” and unzip the same and place in any folder which you want. And write the below sample code to launch firefox and navigate to a particular URL.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class LaunchFirefox
{
    public static void main(String[] args) 
    {
        System.setProperty("webdriver.gecko.driver", "F:\\Selenium\\Drivers\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        // This Site is useful to practice basic Selenium
        driver.get("http://demo.automationtesting.in");
        driver.quit();
    }
}

Launch ChromeBrowser:

To launch chrome browser in selenium 3 we need to download the latest “Chrome Driver” and unzip the same and place in any folder which you want. And write the below sample code to launch chrome and navigate to a particular URL.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class LaunchChrome
{
    public static void main(String[] args) 
    {
       System.setProperty("webdriver.chrome.driver", "F:\\Selenium\\Drivers\\chromedriver.exe");
       WebDriver driver = new ChromeDriver();
       // This Site is useful to practice basic Selenium
       driver.get("http://demo.automationtesting.in");
       driver.quit();
    }
}

Launch EdgeBrowser:

To launch edge browser we need to follow bit different procedure. To get the Edge Driver we need to download the MicrosoftWebDriver from  this link. And it will depends upon the Windows 10 OS build number. For this we need follow below steps:

  1. Go to Start > Settings > System > About  and note down the OS Build number.
  2. Then Download the proper version of the driver from this link
  3. If the downloaded file is .msi, then install it to get the .exe driver. (Not sure, but for the latest version it will directly download the .exe file).
  4. Once the MicrosoftWebDriver.exe is downloaded, Then we can use this .exe file to launch the browser.

And write the below sample code to launch Edge and navigate to a particular URL.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;

public class LaunchEdge
{
    public static void main(String[] args) 
    {
        System.setProperty("webdriver.edge.driver", "F:\\Selenium\\Drivers\\MicrosoftWebDriver.exe");
        WebDriver driver = new EdgeDriver();
        // This Site is useful to practice basic Selenium
        driver.get("http://demo.automationtesting.in");
        driver.quit();
    }
}

These are the ways to launch the different types of browsers in Windows Machine.

Please watch the YouTube video for this blog for better understanding.



Share this post: on Twitter on Facebook

Selenium Webdriver Methods Useful Tools and Plugins in Selenium

Related Posts

TAKING WEB ELEMENT SCREENSHOT IN SELENIUM

Selenium - Java

How to Capture WebElement Screenshot in Selenium Webdriver using selenium 4

avoid Switch to window

Selenium - Java

How to Avoid Switch To Window in Selenium WebDriver

webdrivermanager

Selenium - Java

No More Driver EXE files for Selenium Execution – Instead Use WebDriverManager

HANDLE TEXTBOXES IN SELENIUM

Selenium - Java

Handling Textboxes in Selenium

JAVASCRIPTEXECUTOR IN SELENIUM

Selenium - Java

JavaScriptExecutor in Selenium

ELEMENT NOT VISIBLE EXCEPTION

Selenium - C#, Selenium - Java

Selenium ElementNotVisibleException

NOSUCHWINDOW EXCEPTIONS

Selenium - C#, Selenium - Java

Selenium NoSuchWindowException

NOSUCHFRAME EXCEPTIONS

Selenium - C#, Selenium - Java

Selenium NoSuchFrameException

NOSUCHELEMENT EXCEPTION

Selenium - C#, Selenium - Java

Selenium NoSuchElementException

SELENIUM WEBDRIVER EXCEPTIONS

Selenium - C#, Selenium - Java

Selenium WebDriver Exceptions

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2025