Selenium 是否支持 Safari 浏览器?


是,Selenium webdriver 支持 Safari 浏览器。Safari 是一款著名的浏览器,由 Apple 设备默认提供。对于 Safari 10 及更高版本,safaridriver 会自动安装,不需要单独安装。

SafariDriver 的位置:/usr/bin/safaridriver。另外,请务必记住,要使用 Safari 最新版本,用户必须有 Apple 设备。这是因为 Apple 在 Windows 上不再支持 Safari(自 2012 年起)。

如果我们在 Apple 设备上使用旧版 Safari,我们必须通过运行命令来启用 webdriver 支持 −

/usr/bin/safaridriver −−enable

首先,我们必须导航到Safari,然后单击首选项。选择高级选项,然后选中在菜单栏中显示开发菜单复选框。

然后,从开发菜单中,启用允许远程自动化选项。

示例

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.safari.SafariDriver;
import java.util.concurrent.TimeUnit;
public class LaunchSafariBrw{
   public static void main(String[] args) {
      //object of SafariDriver
      WebDriver driver = new SafariDriver();
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //launch browser
      driver.get("https://tutorialspoint.com/index.htm");
      // close browser
      driver.close();
   }
}

更新于:02-Feb-2021

857 人阅读

开启你的 事业

完成课程以获得认证

开始使用
广告