Skip to main content

To launch a safari browser using selenium you don't need to download driver like chrome or firefox; instead of driver you have to enable few settings on Safari Browser.

Step 1: Go to Safari -> Preferences

preferences in safari

Step 2: Select checkbox Show Develop Menu in menu bar

enable developer menu in Safari

Step 3: From Develop Menu Select Allow Remote Automation

allow selenium remote automation in Safari

Step 4: Add following code to intialize and launch website using Safari Driver.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.testng.annotations.Test;

public class SafariBrowser 
{
    WebDriver driver;
		
    @Test
    public void MyMethod()
    {
        driver = new SafariDriver();
        driver.manage().window().maximize();
        driver.get("http://automationpractice.com");
    }
}

In above code,

  • WebDriver makes direct calls to the browser using each browser’s native support for automation. It uses browser driver for this communication.
  • new SafariDriver(), Here we are creating instance of SafariDriver to launch Safari Browser.
  • driver.get() is used to navigate particular URL of Website.
Video Tutorial

About

Elix is a premium wordpress theme for portfolio, freelancer, design agencies and a wide range of other design institutions.