How To Run Test Cases Using Apple Safari In Selenium Automation Script

It is very similar to run Safari web browser in selenium webdriver tests as other browsers. But you need to do some preparation to make it to be able to listen and understand what webdriver commands means.

SafariDriver change normal client server relationship. It use WebSocket to talk with WebDriver client script. You need to install a web browser extension which just implement the SafariDriver before using it.

SafariDriver can only be run with Safari 5.1+ on windows, As a result, Windows version of it will not work on newer Safari version because Apple has decided to remove windows version of it.

If you have not installed Safari 5.1 on your windows, you can click here or google “apple web browser for windows” to get download link.

If you run selenium webdriver tests script on mac os, you can use Safari 10+ directly. Because Safari 10+ support WebDriver by default.

Now i will show you how to prepare your apple web browser and how to write test script code in java step by step.

How to start using apple web browser in Selenium tests script?

Running selenium automation tests script for multiple web browsers will probably need extra setups, SafariDriver is the same. So you need do following steps.
1. Click here to download the latest extension.
2. Install that extension by double click your downloaded extension file and click “install” in the popup dialog.
Safari driver browser extension download

3. Make sure SafariDriver is enabled by following step.
Go to Safari —> Preferences —> Extensions.
Check “Enable WebDriver” checkbox.
enable safari driver extension

4. Restart this web browser.

How to write java code to launch SafariDriver in selenium webdriver?

Use Safari web browser to run selenium test script is very similar as using IE, Firefox and Chrome. We just need to instantiate SafariDriver class instance to do that. The package for this class is org.openqa.selenium.safari. It support https:// and http:// protocols only and this browser driver can not handle alerts, we should control alerts any time for it in java code.

Below is the example code to use SafariDriver.

 //Instantiate apple WebDriver
 WebDriver sDriver = new SafariDriver();
 //Use apple browser WebDriver to browse webpage
 //Find element on
 WebElement ele = sDriver.findElement(By.xpath("//header[@id=\"masthead\"]/div[1]/h1/a"));
 //Click the web element above.;

[download id=”338″]

0 0 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Oldest Most Voted
Inline Feedbacks
View all comments

Hi safari,

Is there any possibility of running selenium script chrome driver in IPad or Iphone, which is connected to windows 10 laptop.
I want to check the website on both Android and IOS devices but i don’t have mac.


Hi Safari,
Scripts are executing faster than usual. Is there a way to control the speed of the script execution?

Would love your thoughts, please comment.x