Maximizing Safari Browser Compatibility in Selenium Automation


Safari Browser Compatibility

Safari browser is the second most popular browser, with 17.24% of the browser market share. One significant factor contributing to its considerable market share is Safari, being the default browser on all Apple devices. Consequently, web developers worldwide must ensure thorough testing and optimization of their websites for all Safari versions.

The most recent versions of Safari (10 and above) are equipped with a safaridriver, an integrated tool for website debugging. In contrast, previous Safari versions necessitated the Safari WebDriver extension, which is no longer compatible with the latest iterations of the browser. The current Safari browser leverages the Safari driver for the WebDriver protocol.

This article will discuss the key considerations and best practices for seamless integration between Selenium and Safari.

Safari Driver For Selenium Automation Testing

It is essential to have the appropriate Selenium WebDriver installed on the designated machine to ensure effective automation testing with Selenium. For instance, the Chrome WebDriver for Chrome and Geckodriver for Firefox are commonly used options. It is recommended to familiarize oneself with the significance of Selenium and its role in the testing process. In Selenium automation testing with Safari on macOS, it is unnecessary to download a separate Safari driver for Selenium WebDriver.

From Safari 10 onwards on OS X El Capitan and macOS Sierra, the browser offers built-in compatibility with the Selenium WebDriver API. As the Selenium Safari driver for Mac comes preloaded on the operating system, there is no need to specify the executable path when creating the Selenium WebDriver object.

Download Safari Driver for Selenium WebDriver

There is no need to download Safari’s driver separately for use with Selenium WebDriver. Safari is equipped with an integrated driver known as safaridriver, which is typically included in various Selenium client libraries. The maintenance and development of safaridriver is overseen by the web developer experience team at Apple. The executable path for Apple’s safaridriver is usually located at /usr/bin/safaridriver. Additionally, Safari Technology Preview includes its safaridriver executable, typically found within the application’s bundled contents.

The SafariDriver from Safari and SafariDriver from Safari Technology Preview can be operated concurrently, as each individual SafariDriver is designed to initiate the respective Safari browser it is linked to.

The SafariDriver legacy, previously maintained by the Selenium project, has been deprecated and is no longer recommended. Attempting to install the deprecated Selenium WebDriver for Safari may result in an error message from Safari indicating that it no longer supports unsafe extensions.

It is necessary to have Safari 10 (or a later version) installed on the machine to utilize the Selenium safaridriver for automation testing. This is due to the native support available for the Selenium WebDriver API in Safari versions from 10 onwards.

Features Of Selenium Safari Driver On macOS

Additional safeguards have been implemented to accommodate WebDriver functionality while upholding user privacy and security to ensure that Selenium test execution remains completely isolated from standard browsing data and other test runs.

Here are a few features of the Selenium Safari driver on macOS:

Isolated Automation Windows

The safariDriver created by Apple’s team of experienced web developers ensures that the execution of tests and automation scenarios using Selenium is contained within dedicated automation windows. This segregation ensures that tests run using the Safari driver remain separate from regular browsing windows, user settings, and preferences.

Just as automation testing is carried out using geckodriver for Firefox, Safari windows undergoing tests can be recognized by their distinctive orange Smart Search field.

Similar to a private browsing session in Safari, automation tests utilizing Apple’s safaridriver begin anew to ensure that the persistent state of the previous test session does not impact the newly initiated Selenium test automation scenario.

WebDriver commands for Debugging

The Safari driver for Selenium on macOS allows users to specify WebDriver capabilities in a New Session for debugging purposes. When the capability Safari:automaticInspection is passed in a New Session request, the safaridriver preloads Web Inspector and JavaScript debugger in the background. This feature enables users to pause test execution and inspect execution details in the Debugger tab of Web Inspector, similar to the functionality provided by the Inspect tool.

Upon activation of the Safari:automaticProfiling capability in a New Session request, the safaridriver initiates preloading of Web Inspector and commences timeline recording in the background. For additional information, users can access the Timeline tab within the Web Inspector interface.

Glass Pane

A glass pane has been installed over the Safari window to facilitate the ongoing execution of the automation test. This pane is designed to prevent any manual interactions, such as mouse movements, keyboard inputs, resizing, closing, minimizing, etc., that could potentially disrupt the automated testing process within the Automation Window.

If the ongoing test becomes unresponsive or encounters a failure, or if manual verification within the automation window is required, there is a method to terminate the test. Breaking the glass pane facilitates the interruption of the Selenium test automation session while allowing the automation window to remain accessible for manual inspection until it is manually closed.

Below is the popup window that arrives when trying to break the WebDriver Session:

Stop Session: This function terminates the current WebDriver session, allowing for continued interaction with the browser.

Turn off All Automation: This feature will deactivate the ‘Develop > Allow Remote Automation’ option, which is necessary for utilizing the Selenium Safari driver on macOS to execute automation tests. To resume running tests in the Safari browser, the command ‘safaridriver –enable’ must be re-executed in the terminal.

Continue Session: Selecting this option will resume the session, allowing the test to continue from where it was paused. Please note that once this option is chosen, you cannot interact with the browser.

Web Inspector

The Web Inspector tool is a valuable resource that can be utilized before and after the execution of Selenium WebDriver tests. Its capabilities include identifying information about web elements, monitoring network performance, recording performance data, and more. These features remain fully operational when executing Selenium test automation scenarios.

The “Develop > Show Web Inspector” menu option activates the inspection tool during the execution of Selenium WebDriver tests.

One Session At A Time

During automation testing, it is necessary to note that only one WebDriver session can be attached to an instance of the Safari browser at a time. This means that only one Safari instance can be active with its corresponding WebDriver session during the testing process.

According to the official Apple blog, the constraints outlined ensure that the tests do not internally compete for resources such as window focus, keyboard events, and keyboard focus. These constraints are aligned with the functionalities available within a macOS windowing environment.

Maximizing Safari Browser Compatibility in Selenium Automation

Selenium is an open-source automated testing framework designed for web applications. It enables developers and quality assurance professionals to perform automated testing across multiple browsers, including Safari. However, ensuring compatibility with the Safari browser can be challenging due to its unique features and constant updates. As a result, maximizing Safari browser compatibility has become a crucial aspect of Selenium automation.

Here are a few practices for achieving seamless integration between Selenium and Safari:

Explore the different Browser Options

Although Safari is commonly utilized for testing on macOS and iOS devices, exploring alternative browsers for thorough coverage and precise testing outcomes is advisable. Chrome, Firefox, and Edge present distinct features and functionalities that can help pinpoint any discrepancies or challenges unique to Safari.

Implement Proper Error-Handling Techniques

Achieving optimal Safari browser compatibility in Selenium automation necessitates implementing effective error-handling techniques. Error handling is integral in identifying and resolving issues that may occur throughout the automation process.

Developers can enhance error-handling capabilities by implementing robust mechanisms to capture and manage exceptions effectively. This approach helps prevent automation scripts from abruptly failing, ensuring that any encountered errors during execution are handled gracefully to maintain smooth automation flow.

Stay updated on Browser Updates

Safari, like all other web browsers, issues routine updates that frequently encompass significant security patches, bug fixes, and performance improvements. Keeping abreast of these updates allows automation teams to guarantee that their scripts operate on the most recent Safari version, reducing the likelihood of facing compatibility dilemmas or unforeseen malfunctions.

Routinely monitoring and promptly implementing updates are advised to ensure the optimal performance of Selenium automation across various Safari versions. By proactively staying informed about browser updates, teams can sustain a resilient and dependable automation framework that aligns with the latest Safari browser.

Use CSS Selectors for Robustness

CSS selectors are essential for ensuring compatibility with the Safari browser in Selenium automation. Through the strategic use of CSS selectors, automation teams can develop robust and dependable scripts that are resilient to modifications in the DOM structure or styling of web elements.

CSS selectors offer a robust and versatile method for identifying elements within a web page, enabling automation scripts to precisely and effectively target specific elements. This capability enhances the stability of automation tests and contributes to the overall maintainability of the codebase.

Avoid unsupported features in Safari

To ensure maximum Safari browser compatibility in Selenium automation, avoid using unsupported features in Safari. It is recommended that comprehensive research be conducted on the compatibility of HTML5, CSS3, and JavaScript features with the Safari browser to avoid potential issues or errors in automation scripts. Understanding Safari’s supported features and constraints is crucial for effectively designing and implementing automation tests.

To maintain consistent and reliable script execution across various Safari versions, automation teams should prioritize using supported features and compatible alternatives. This proactive strategy mitigates the likelihood of facing compatibility issues and promotes a streamlined automation process.

Utilize Cloud-Based Testing Platforms

Cloud-based testing platforms provide a convenient and efficient solution for cross-browser testing without setting up and managing numerous physical devices or virtual machines. These platforms enable automation teams to access various devices and operating systems, including various versions of Safari, simplifying comprehensive test coverage. This capability aids in identifying browser-specific issues or discrepancies that could arise when executing automation scripts on Safari.

Cloud-based testing platforms like LambdaTest can adjust testing resources according to requirements, resulting in accelerated turnaround times and improved efficiency. LambdaTest is an AI-powered test orchestration and execution platform to run manual and automated tests at scale. The platform allows you to perform both real-time and automation testing across 3000+ environments and real mobile devices.

Leveraging cloud-based testing platforms enables organizations to optimize their testing procedures, improve compatibility with Safari browsers, and deliver superior web applications to their users.


By incorporating the strategies and methodologies outlined in this article, developers and testers can enhance the compatibility of their automation scripts for seamless execution on Safari, a prominent browser in widespread use. By paying meticulous attention to detail and acquiring a comprehensive grasp of Safari’s distinct functionalities, Selenium automation can be fine-tuned to facilitate dependable and effective testing on this browser platform.

Leave a Comment