Check out my iOS apps here
As an Amazon Associate I earn from qualifying purchases.

How to launch Safari using Selenium Web Driver (Mac OS & Mac OSX)

Launching Safari Using Selenium Web Driver Is Slightly Different, Here’s How To Do It

Safari is the main browser that comes with Apple devices, both Mac & iOS. Because it was discontinued from Windows in 2012, using it with Selenium can only be done on a Mac machine. Unlike the other browsers, like Chrome & Firefox, which I explained how to launch in my lesson about launching different browsers ☇. Launching Safari with Selenium web driver requires different steps. In this tutorial, I will explain how to do these steps.

Enabling Remote Automation From Safari

Safari supports remote automation natively, but to be able to do automated tests (or to use it for scarping), you will need to enable the Remote Automation feature. Which is found in the Develop menu. That menu is hidden by default, so let’s change the preference so that it’s shown.

    • Select Safari->Preferences to open the Preferences Window.
    • Once the preference window is shown, go to the advanced tab. At the bottom of the window, check the “Show Develop menu in menu bar” checkbox.
    • Close the window.
    • After that, the Develop menu is shown in Safari now.
    • From the Develop menu. Select Allow Remote Automation.
    • Now, Safari is ready to be launched from Selenium.



Launching Safari Using Selenium Web Driver

Unlike the other browsers, we don’t need to download a driver from Selenium website. As Selenium has a Safari driver built-in. So once you enable Remote Automation in Safari, you can write the code to launch Safari right away. This is simply done by creating an instance of SafariDriver, which you can interact with just like any other WebDriver instance. The following code does that, and then it opens Tech-Fairy.com home page:-

package SeleniumTutorial;
import org.openqa.selenium.*;
import org.openqa.selenium.safari.SafariDriver;
public class LaunchSafariWithSelenium {
public static void main(String[] args) {
WebDriver driver = new SafariDriver();
driver.get("http://tech-fairy.com/");
driver.close();
}
}

And Finally

I hope this lesson made it easier for you to launch Safari using Selenium Web Driver, and see you again in another lesson.

See Also:-

Leave a Comment

Your email address will not be published. Required fields are marked *