ScreenshotNeo

BlogHow-to

How to Set Up SafariDriver on macOS for Selenium Testing

Enable Safari’s built-in WebDriver on macOS, configure Selenium, and fix common SafariDriver setup errors.

By the ScreenshotNeo team4 October 20266 min read

To run Selenium tests in Safari on macOS, enable Safari’s built-in WebDriver, then create a Safari session with a current Selenium client library. In Safari, open Develop > Developer Settings… and turn on Allow remote automation, or run safaridriver --enable in Terminal. SafariDriver is supplied with macOS, so you normally do not download a separate driver binary. Apple’s enablement guide and Selenium’s Safari guide document the setup.

1. Enable Safari WebDriver

Choose either the Safari settings interface or Terminal. Both enable the same remote automation capability on current macOS versions.

Option A: Safari settings

  1. Open Safari.
  2. Open the Develop menu and choose Developer Settings….
  3. Check Allow remote automation.

If you do not see the Develop menu, open Safari’s settings and enable the Develop menu in the advanced settings. Menu labels can vary slightly by Safari and macOS version.

Option B: Terminal

safaridriver --enable

On a Mac upgraded from an earlier macOS release, Apple notes that sudo may be required:

sudo safaridriver --enable

Use the elevated command only if the regular command does not enable automation and the Mac’s upgrade history matches Apple’s guidance. Safari’s WebDriver support is turned off by default. See Apple’s current instructions.

2. Install Selenium and create a Safari session

Install the Selenium client for your test language, then use its Safari driver. Selenium generally launches the OS-provided SafariDriver automatically; you do not need to fetch a driver from a separate browser-driver download site.

Python example

Install Selenium:

python3 -m pip install selenium

Save this as safari_smoke.py and run it with python3 safari_smoke.py:

from selenium import webdriver
from selenium.webdriver.common.by import By


def main():
    driver = webdriver.Safari()
    try:
        driver.get("https://example.com")
        print("Title:", driver.title)
        heading = driver.find_element(By.TAG_NAME, "h1")
        print("Heading:", heading.text)
    finally:
        driver.quit()


if __name__ == "__main__":
    main()

Java example

Add Selenium WebDriver to your project using the dependency manager and version you use for the rest of your Selenium tests. For Maven, the dependency is org.seleniumhq.selenium:selenium-java. Then:

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

public class SafariSmokeTest {
    public static void main(String[] args) {
        WebDriver driver = new SafariDriver();
        try {
            driver.get("https://example.com");
            System.out.println("Title: " + driver.getTitle());
        } finally {
            driver.quit();
        }
    }
}

JavaScript example

Install the Selenium JavaScript package:

npm install selenium-webdriver

Save as safari-smoke.js and run with Node.js:

const { Builder, By } = require('selenium-webdriver');
const safari = require('selenium-webdriver/safari');

(async function main() {
  const options = new safari.Options();
  const driver = await new Builder()
    .forBrowser('safari')
    .setSafariOptions(options)
    .build();

  try {
    await driver.get('https://example.com');
    console.log('Title:', await driver.getTitle());
    const heading = await driver.findElement(By.css('h1'));
    console.log('Heading:', await heading.getText());
  } finally {
    await driver.quit();
  }
})();

3. Choose Safari or Safari Technology Preview

The standard driver executable is /usr/bin/safaridriver. Safari Technology Preview has a separate executable inside its application bundle. Each driver is associated with its corresponding Safari build, so select the matching executable when your Selenium client supports configuring the driver location.

Do not point a Safari Technology Preview test at the standard Safari driver and assume it will launch the preview browser. Confirm the application bundle path on the machine, then configure the Selenium library’s Safari service or driver path option according to that library’s current documentation. Selenium’s Safari browser guide covers its client-side configuration. Apple’s WebKit WebDriver guide describes the separate executables and their browser-version association.

4. Understand what the Safari session controls

Safari WebDriver sessions use isolated test windows. Apple describes them as separate from normal browsing windows, settings, and preferences. This helps keep automation separate from your everyday Safari session, but do not assume that a test has access to your personal window state or browser data. See Apple’s WebDriver overview.

Use the normal Selenium APIs for navigation, element lookup, assertions, and cleanup. Always call quit() in a finally block or test-framework teardown so a failed assertion does not leave the automation session running.

5. Run a first test and verify the setup

  1. Enable remote automation in Safari or with safaridriver --enable.
  2. Install a current Selenium client library for your language.
  3. Run a small smoke test against a page you can access.
  4. Check that Safari opens, the page loads, and the test can read a title or element.
  5. Close the session with the Selenium driver’s quit() method.

If the session starts, the browser opens, and the test can interact with the page, the basic setup is complete. Add your application-specific assertions and test framework hooks next.

Or skip the browser setup

If your task is to capture a page image or PDF rather than interactively test browser behavior, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF. The one-call version is:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for parameters and formats. ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. See ScreenshotNeo for the service and sign up for 1,000 free screenshots a month with no card.

Troubleshooting

Symptom Likely cause What to do
Safari says remote automation is disabled WebDriver remains off, or the enable command was not applied. Turn on Allow remote automation in Developer Settings or run safaridriver --enable. On an upgraded older installation, consult Apple’s note about using sudo.
safaridriver: command not found The shell cannot find the OS-provided executable or the command was entered in a non-macOS environment. Run on the Mac that has Safari installed. Check /usr/bin/safaridriver; use that path explicitly to determine whether the executable exists.
Safari starts, but the test targets the wrong browser The standard Safari and Safari Technology Preview drivers are distinct. Choose the executable associated with the desired Safari build and configure the client library to use it.
A legacy setup guide asks for a Selenium SafariDriver download It describes the older Selenium-maintained implementation. Use Apple’s native SafariDriver with a current Selenium client. Apple’s WebKit guide says its implementation replaced the old one.
Test fails to find an element immediately after navigation The page may not have rendered the element when the lookup ran. Use Selenium explicit waits for the expected condition instead of relying on a fixed short sleep. Keep the wait bounded so a real page failure surfaces.
Safari session remains open after an assertion fails Driver cleanup did not execute. Place driver.quit() in a finally block or your test framework’s teardown hook.

Performance, reliability, and cost

  • Setup cost: The Safari driver is included with macOS, so ordinary setup does not require a separate driver download. You still need a Selenium client library in your project.
  • Runtime: Browser startup and page load time are part of each test. Keep tests focused, use explicit waits for specific conditions, and close each session promptly.
  • Reliability: Safari automation depends on the macOS host, its installed Safari build, the enabled remote automation setting, and the page under test. Pin and document the Selenium client version used by your project, and run Safari tests on a Mac with the intended browser target.
  • CI: Run the setup command and browser test in the macOS environment that executes the job. A setting enabled on a developer’s laptop does not enable it on a separate CI host.
  • Cost: This workflow uses the OS-bundled browser driver and a Selenium client library; the research sources specify no additional SafariDriver charge. Costs for CI hosts or other infrastructure depend on your environment.

FAQ

Do I need to download SafariDriver separately?

No. SafariDriver is installed with macOS and is commonly launched by Selenium.

Does enabling WebDriver change my normal Safari windows?

Apple describes WebDriver test windows as isolated from normal browsing windows, settings, and preferences.

Can I use Safari Technology Preview?

Yes. Use its associated driver executable and configure the Selenium client to target that executable.

Should I use the old Selenium SafariDriver implementation?

No. Use Apple’s native implementation through a current Selenium client library; Apple’s WebKit guide documents that it replaced the old implementation.

Where can I confirm the current enablement steps?

Use Apple’s SafariDriver enablement documentation, since menu details and operating-system behavior can change between releases.