如何使用 Java 使用 Selenium WebDriver 启动 Safari
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26598239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to launch Safari with Selenium WebDriver using Java
提问by user3866016
I have successfully installed safari developer certificate for safari driver. I have been built and added to safari extensions builder. The presteps are done. However when I run my selenium scripts, the safari server starts on a port and then I get following error in my eclipse console as shown below:
我已成功为 safari 驱动程序安装了 safari 开发人员证书。我已经构建并添加到 safari 扩展构建器。准备工作已完成。但是,当我运行 selenium 脚本时,safari 服务器在一个端口上启动,然后在 eclipse 控制台中出现以下错误,如下所示:
Oct 27, 2014 3:49:37 PM org.openqa.selenium.safari.SafariDriverServer start
INFO: Server started on port 22131
java.lang.IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.openqa.selenium.safari.SafariDriverCommandExecutor
at org.openqa.selenium.safari.SafariDriverCommandExecutor.start(SafariDriverCommandExecutor.java:99)
at org.openqa.selenium.safari.SafariDriver.startClient(SafariDriver.java:115)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:101)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:94)
The safari browser open with giving error "Safari cant Find the File"
Safari 浏览器打开时出现错误“Safari 无法找到文件”
Any help would be appriciated thanks
任何帮助都会被感谢
采纳答案by Vinu Joseph
Hi,
Setting up Selenium tests to run on Safari browser is a fairly complex process. You need to install Safari Extensions Developer Certificate in your machine and also install selenium webdriver as an extension in Safari Browser.
嗨,
设置 Selenium 测试以在 Safari 浏览器上运行是一个相当复杂的过程。您需要在您的机器上安装 Safari Extensions Developer Certificate,并在 Safari Browser 中安装 selenium webdriver 作为扩展。
Also there are some stability issues with Safari browser automation & Selenium combination on Mac 10.9 OS and below. The stability is much better on Mac Yosemite OSX & Safari 8.0.x combination along with Selenium v2.45.0
Mac 10.9 OS 及更低版本上的 Safari 浏览器自动化和 Selenium 组合也存在一些稳定性问题。Mac Yosemite OSX 和 Safari 8.0.x 组合以及 Selenium v2.45.0 的稳定性要好得多
Detailed steps for the setup can be seen here
设置的详细步骤可以在这里看到
Regards,
VJ
问候,
VJ
回答by Anirudh
It might be a problem related to Webdriver version, please use the latest Webdriver version, Safari driver comes bundled with the the Webdriver just like the firefox driver and you could simply invoke the driver using the code below:
可能是 Webdriver 版本的问题,请使用最新的 Webdriver 版本,Safari 驱动程序与 Webdriver 捆绑在一起,就像 firefox 驱动程序一样,您可以使用以下代码简单地调用驱动程序:
SafariOptions options = new SafariOptions();
options.setUseCleanSession(true); //if you wish safari to forget session everytime
dvr = new SafariDriver(options);
回答by user1208710
Starting with Selenium 2.30.0, the SafariDriver comes bundled with the Selenium server. If you wish to build the driver from source, head over to the SafariDriverInternals page. For now, grab a copy of the Selenium jar and add it to your classpath. Writing a test for Safari is just as straightforward as using the FirefoxDriver: To manually install the latest Safari extension (2.43.1): -
从 Selenium 2.30.0 开始,SafariDriver 与 Selenium 服务器捆绑在一起。如果您希望从源代码构建驱动程序,请转到 SafariDriverInternals 页面。现在,获取 Selenium jar 的副本并将其添加到您的类路径中。为 Safari 编写测试与使用 FirefoxDriver 一样简单:手动安装最新的 Safari 扩展 (2.43.1):-
-
——
Download Safari Driver jar from here: http://central.maven.org/maven2/org/seleniumhq/selenium/selenium-safari-driver/2.43.1/selenium-safari-driver-2.43.1.jar. Rename the file to a .zip file instead of a .jar file. Unzip it (just double click on it to do so). In Folder, go to /selenium-safari-driver-2.43.1/org/openqa/selenium/safari. Double click “SafariDriver.safariextz” or simple drag this file in browser.
System.setProperty("webdriver.safari.noinstall", "true"); //To stop uninstall each time driver = new SafariDriver(); driver.get("Url");
从这里下载 Safari 驱动程序 jar:http: //central.maven.org/maven2/org/seleniumhq/selenium/selenium-safari-driver/2.43.1/selenium-safari-driver-2.43.1.jar。将文件重命名为 .zip 文件而不是 .jar 文件。解压缩它(只需双击它即可)。在文件夹中,转到 /selenium-safari-driver-2.43.1/org/openqa/selenium/safari。双击“SafariDriver.safariextz”或在浏览器中简单地拖动此文件。
System.setProperty("webdriver.safari.noinstall", "true"); //To stop uninstall each time driver = new SafariDriver(); driver.get("Url");
回答by Jlearner
In latest Safari (10.0.1 as of today Nov 2016) WebDriver support is turned off by default. To turn on WebDriver support, do the following:
在最新的 Safari(截至 2016 年 11 月的 10.0.1)中,WebDriver 支持默认关闭。要打开 WebDriver 支持,请执行以下操作:
- Ensure that the Develop menu is available. It can be turned on by opening Safari preferences (Safari > Preferences in the menu bar), going to the Advanced tab, and ensuring that the Show Develop menu in menu bar checkbox is checked.
- Enable Remote Automation in the Develop menu. This is toggled via Develop > Allow Remote Automation in the menu bar.
- Authorize safaridriver to launch the webdriverd service which hosts the local web server. To permit this, once manually run safaridriver which is present at path
/usr/bin/safaridriver
and complete the authentication prompt.
- 确保“开发”菜单可用。可以通过打开 Safari 首选项(菜单栏中的 Safari > 首选项)打开高级选项卡,并确保选中在菜单栏中显示开发菜单复选框。
- 在开发菜单中启用远程自动化。这是通过菜单栏中的“开发”>“允许远程自动化”切换的。
- 授权 safaridriver 启动托管本地 Web 服务器的 webdriverd 服务。要允许此操作,请手动运行路径中存在的 safaridriver
/usr/bin/safaridriver
并完成身份验证提示。
Now safari is ready to run your webdriver scripts. For more details click here
现在 safari 已准备好运行您的 webdriver 脚本。欲了解更多详情,请点击此处