Working with other Browsers…

Selenium scripts work with multiple browsers. In our first script we used Chrome browser and for executing the script in Chrome browser we had to set properties for Chrome Driver. In this post I will be mainly focusing on setting properties for other browsers. Before working with different browsers, make sure the browsers are installed on your machine. This is a prerequisite for executing the script in different browsers.

Safari: 

Safari browser now provides native support for the WebDriver API. This means that you don’t have to download the Safari driver from third party section like we did for Chrome browser. Just change the System Properties as mentioned below and the scripts works just fine in Safari. You can copy the code from ‘FirstScript’ in ‘com.selenium.firstscript’ package and paste the script in a new class file ‘SecondScript’. Change the System properties and driver information as displayed below.

Screen Shot 2017-02-20 at 12.50.55 PM.png
Safari Driver

Firefox:

With Selenium 3, for executing the scripts in Firefox browser, we will have to download the GeckoDriver. You can go to Selenium Website, go to Downloads, and then to ‘Third Party Drivers, Bindings, and Plugins’ section. Click the ‘Mozilla GeckoDriver’ link to go to download page.

URL: Selenium Download

Once you reach the GeckoDriver page, download the latest driver package based on your Windows/Mac OS to your local folder. Follow the same step for Chrome Browser download i.e. create a new folder ‘Firefox’ inside your root directory of the Java project that we created earlier. Copy the downloaded executable file into the ‘Firefox’ folder. Once done, create a new class file called ‘ThirdScript’ and copy paste the code from ‘FirstScript’ or ‘SecondScript’ file. Now we have to update the System properties and the driver information in the ‘ThirdScript.java’ file as mentioned below.

screen-shot-2017-02-20-at-2-00-05-pm
Firefox Driver

IE:

You need to download the MS Edge driver from the Selenium website and repeat the same steps of Chrome/Firefox browsers. The only difference is on the below code. Use these codes for IE browser:

System.setProperty("webdriver.ie.driver", "System.getProperty("user.dir") + "/IE/IEdriver"");
WebDriver driver = new InternetExplorerDriver();

Please note for Window OS, always use ‘\\’ instead of ‘/’ for setting the driver to correct location.

Note: When using MAC, to make the Driver executable, we have to run below command in Terminal where the driver is placed:
chmod +x chromedriver