How to Run Safari Driver in Selenium Using Java?
Selenium is a well-known software used for software testing purposes. Selenium consists of three parts: Selenium IDE, Selenium Webdriver, and Selenium Grid. Among these, Selenium Webdriver is the most important one. Using Webdriver, online website testing can be done. There are three main Webdrivers present. For the Chrome browser, ChromeDriver is present. For the Firefox browser, Gecko Driver is applicable; for Microsoft Edge, there will be MSEdgeDriver. Excluding these, many more drivers are present for other browsers.
In this article, the process of running SafariWebdriver is implemented. It is useful for those who use Mac OS. This simple Java program can be run
Table of Content
Pre-Requisites
- To run SafariDriver, the Java JDK version must have previously been installed on the machine.
- The latest version of Safari should be installed.
- It is preferable to install Eclipse IDE on the machine so that running this code will be easier.
- The most important prerequisite is latest SafariDriver should be downloaded on the machine.
Proper Steps to Run Selenium Tests on Safari
1. Ensure Prerequisites
Before you begin, make sure you have the following prerequisites:
- Java Development Kit (JDK): Installed and configured on your system.
- Eclipse IDE or another Java IDE: For writing and executing Java code.
- Selenium WebDriver: Download the Selenium Java client driver JAR file from Selenium's website.
- Safari Browser: Installed on macOS.
- SafariDriver: Pre-installed with macOS Safari version 10 or later.
2. Enable Safari's Driver
SafariDriver needs to be enabled in Safari:
- Open Safari.
- Go to Safari > Preferences (or press Cmd + ,).
- Click on the Advanced tab.
- Check the Show Develop menu in menu bar option.
- From the Develop menu, select Allow Remote Automation.

3. Set Up Your Project
Create a New Java Project
- Open Eclipse (or your preferred IDE).
- Go to File > New > Java Project.
- Name your project (e.g., SafariTestProject) and click Finish.
Add Selenium WebDriver Library
- Download the Selenium Java client driver JAR file.
- Right-click on your project in Eclipse.
- Select Build Path > Add External Archives.
- Browse to the JAR file and add it.
4. Write the Selenium Test Script
Create a New Java Class
- Right-click on src in your project.
- Select New > Class.
- Name the class (e.g., SafariTest) and click Finish.
Below is the complete implementation of the above approach:
// Importing All Necessary Items
import java.io.*;
import java.lang.Thread;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.safari.SafariDriver;
public class GoogleHomePage {
public static void main(String[] args)
{
// Try-Catch Block For Implementing Sleep Method
try {
// String Where Home Page URL Is Stored
String baseUrl = "https://www.google.com/";
// Implementation of SetProperty Method
System.setProperty(
"webdriver.safari.driver",
"test/resources/safaridriver.exe");
// Creating New Object driver Of Webdriver
WebDriver driver = new SafariDriver();
// Calling the Home Page By Using Get() Method
driver.get(baseUrl);
// Delaying The Output
Thread.sleep(2000);
// Closing The Opened Window
driver.quit();
}
catch (Exception e) {
// Catching The Exception
System.out.println(e);
}
}
}
Output:
If the above code is run, then a new Safari Window will be opened. This open window will be controlled by SafariDriver.exe.

Hence, the program runs successfully.
Conclusion
If you follow the following steps, running Selenium tests on Safari with SafariDriver is a simple task. SafariDriver's integration with Safari makes it simple to automate web testing on macOS. You can make sure that everything runs smoothly and that tests are trustworthy by updating your drivers and software and adhering to the recommended setup guidelines.