The Problem
Running your Selenium tests on a different browser tends to require additional setup, and SafariDriver is no exception.A Solution
Since Selenium 2.45.0, in order to use SafariDriver, you need to manually install the SafariDriver browser extension. Let’s step through how to do it and make sure it’s working.An Example
The prebuilt SafariDriver extension can be downloaded from here (the link is listed in the Getting Started section of the SafariDriver Selenium Wiki). Download it, double-click it, and clickTrust
when prompted. After that, make sure it’s enabled. To do that:- open
Safari
- go to
Preferences
- click on the
Extensions
tab - Make sure
Enable WebDriver
is checked - Close
Safari

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.safari.SafariDriver;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
public class Safari {
WebDriver driver;
@Before
public void setUp() throws Exception {
driver = new SafariDriver();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void dropdownTest() {
driver.get("http://the-internet.herokuapp.com/");
String title = driver.getTitle();
assertThat(title, is(equalTo("The Internet")));
}
}

Expected Behavior
When you save the file and run it (e.g.,mvn clean test
from the command-line), here is what will happen:- Safari opens
- The home page of the-internet loads
- The title of the page is checked to make sure it’s what we expect
- Safari closes