Safari specific functionality These are capabilities and features specific to Apple Safari browsers.
Unlike Chromium and Firefox drivers, the safaridriver is installed with the Operating System.
To enable automation on Safari, run the following command from the terminal:
Options Capabilities common to all browsers are described on the Options page .
Capabilities unique to Safari can be found at Apple’s page About WebDriver for Safari
Starting a Safari session with basic defined options looks like this:
Move Code
Java
Python
CSharp
Ruby
JavaScript
Kotlin /examples/java/src/test/java/dev/selenium/browsers/SafariTest.java
Copy
Close
package dev.selenium.browsers ;
import org.junit.jupiter.api.AfterEach ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.api.condition.EnabledOnOs ;
import org.junit.jupiter.api.condition.OS ;
import org.openqa.selenium.safari.SafariDriver ;
import org.openqa.selenium.safari.SafariOptions ;
@EnabledOnOs ( OS . MAC )
public class SafariTest {
public SafariDriver driver ;
@AfterEach
public void quit () {
driver . quit ();
}
@Test
public void basicOptions () {
SafariOptions options = new SafariOptions ();
driver = new SafariDriver ( options );
}
}
def test_basic_options ():
options = SafariOptions ()
/examples/python/tests/browsers/test_safari.py
Copy
Close
import sys
import pytest
from selenium import webdriver
from selenium.webdriver.safari.options import Options as SafariOptions
@pytest.mark.skipif ( sys . platform != "darwin" , reason = "requires Mac" )
def test_basic_options ():
options = SafariOptions ()
driver = webdriver . Safari ( options = options )
driver . quit ()
/examples/dotnet/SeleniumDocs/Browsers/SafariTest.cs
Copy
Close
using Microsoft.VisualStudio.TestTools.UnitTesting ;
using OpenQA.Selenium.Safari ;
using SeleniumDocs.TestSupport ;
namespace SeleniumDocs.Browsers
{
[TestClassCustom]
[EnabledOnOs("OSX")]
public class SafariTest
{
[TestMethod]
public void BasicOptions ()
{
var options = new SafariOptions ();
var driver = new SafariDriver ( options );
driver . Quit ();
}
}
}
@driver = Selenium :: WebDriver . for :safari , options : options
end
/examples/ruby/spec/browsers/safari_spec.rb
Copy
Close
# frozen_string_literal: true
require 'spec_helper'
RSpec . describe 'Safari' , exclusive : { platform : :macosx } do
it 'basic options' do
options = Selenium :: WebDriver :: Options . safari
@driver = Selenium :: WebDriver . for :safari , options : options
end
end
describe ( 'Should be able to Test Command line arguments' , function () {
( process . platform === 'darwin' ? it : it . skip )( 'headless' , async function () {
let driver = await env . builder ()
. setSafariOptions ( options )
/examples/javascript/test/browser/safariSpecificCap.spec.js
Copy
Close
const safari = require ( 'selenium-webdriver/safari' );
const { Browser } = require ( "selenium-webdriver" );
const { suite } = require ( 'selenium-webdriver/testing' )
const options = new safari . Options ();
const process = require ( 'node:process' );
suite ( function ( env ) {
describe ( 'Should be able to Test Command line arguments' , function () {
( process . platform === 'darwin' ? it : it . skip )( 'headless' , async function () {
let driver = await env . builder ()
. setSafariOptions ( options )
. build ();
await driver . get ( 'https://www.google.com' );
await driver . quit ();
});
});
}, { browsers : [ Browser . SAFARI ]});
val options = SafariOptions ()
val driver = SafariDriver ( options )
Mobile Those looking to automate Safari on iOS should look to the Appium project .
Service Service settings common to all browsers are described on the Service page .
Logging Unlike other browsers, Safari doesn’t let you choose where logs are output, or change levels. The one option
available is to turn logs off or on. If logs are toggled on, they can be found at:~/Library/Logs/com.apple.WebDriver/
.
Java
Python
CSharp
Ruby
JavaScript
Kotlin Selenium v4.10
/examples/java/src/test/java/dev/selenium/browsers/SafariTest.java
Copy
Close
package dev.selenium.browsers ;
import org.junit.jupiter.api.AfterEach ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.api.condition.EnabledOnOs ;
import org.junit.jupiter.api.condition.OS ;
import org.openqa.selenium.safari.SafariDriver ;
import org.openqa.selenium.safari.SafariOptions ;
@EnabledOnOs ( OS . MAC )
public class SafariTest {
public SafariDriver driver ;
@AfterEach
public void quit () {
driver . quit ();
}
@Test
public void basicOptions () {
SafariOptions options = new SafariOptions ();
driver = new SafariDriver ( options );
}
}
Note : Java also allows setting console output by System Property; Property key: SafariDriverService.SAFARI_DRIVER_LOGGING
Property value: "true"
or "false"
Selenium v4.26
/examples/python/tests/browsers/test_safari.py
Copy
Close
import sys
import pytest
from selenium import webdriver
from selenium.webdriver.safari.options import Options as SafariOptions
@pytest.mark.skipif ( sys . platform != "darwin" , reason = "requires Mac" )
def test_basic_options ():
options = SafariOptions ()
driver = webdriver . Safari ( options = options )
driver . quit ()
Selenium v4.8
/examples/ruby/spec/browsers/safari_spec.rb
Copy
Close
# frozen_string_literal: true
require 'spec_helper'
RSpec . describe 'Safari' , exclusive : { platform : :macosx } do
it 'basic options' do
options = Selenium :: WebDriver :: Options . safari
@driver = Selenium :: WebDriver . for :safari , options : options
end
end
Safari Technology Preview Apple provides a development version of their browser — Safari Technology Preview
Java
Python
CSharp
Ruby
JavaScript
Kotlin /examples/java/src/test/java/dev/selenium/browsers/SafariTest.java
Copy
Close
package dev.selenium.browsers ;
import org.junit.jupiter.api.AfterEach ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.api.condition.EnabledOnOs ;
import org.junit.jupiter.api.condition.OS ;
import org.openqa.selenium.safari.SafariDriver ;
import org.openqa.selenium.safari.SafariOptions ;
@EnabledOnOs ( OS . MAC )
public class SafariTest {
public SafariDriver driver ;
@AfterEach
public void quit () {
driver . quit ();
}
@Test
public void basicOptions () {
SafariOptions options = new SafariOptions ();
driver = new SafariDriver ( options );
}
}
/examples/python/tests/browsers/test_safari.py
Copy
Close
import sys
import pytest
from selenium import webdriver
from selenium.webdriver.safari.options import Options as SafariOptions
@pytest.mark.skipif ( sys . platform != "darwin" , reason = "requires Mac" )
def test_basic_options ():
options = SafariOptions ()
driver = webdriver . Safari ( options = options )
driver . quit ()
/examples/ruby/spec/browsers/safari_spec.rb
Copy
Close
# frozen_string_literal: true
require 'spec_helper'
RSpec . describe 'Safari' , exclusive : { platform : :macosx } do
it 'basic options' do
options = Selenium :: WebDriver :: Options . safari
@driver = Selenium :: WebDriver . for :safari , options : options
end
end