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.
Quickly go to:-
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:-
-
- Introduction to selenium web driver series. What is it? And what browsers & programming languages it supports – Tech Fairy
- What are 60% Keyboards (65%)? And what are their advantages & disadvantages – Tech Fairy
- 40% Keyboards Form Factor, What are they? And why would you use one? – Tech Fairy
- Why ThinkPad laptops are popular, and what are their advantages?
- What are business-grade laptops? What are their advantages? And which one to buy?
- Java VS Python VS C# detailed comparison, which language to learn first?
- Do you need an Expensive motherboard for gaming?
- What is the meaning of the different USB port colors? (blue, teal blue, yellow, red, black)
- Why motherboards & laptops still come with USB 2.0 ports When USB 3.0 Is Backward Compatible?
- USB 2.0 VS USB 3.0 Comparison: What are the differences between the two ports?