我在 Mac OSX 10.8.5 和 Java 7 Update 55 上使用 selenium-server-standalone-2.41.0.jar。
在 25.0.1 版本之前的 Firefox 上一切正常,但如果我尝试 Firefox v26、v27、v28 或 v29,那么我的代码将打开 Firefox,并且它会挂起(Firefox 屏幕上不会加载任何内容)。
当我将 Firefox 降级回 v25 时,一切又开始正常工作。
有什么想法或建议吗?
谢谢
编辑:也在 Selenium bug 论坛上发布了问题: https://code.google.com/p/selenium/issues/detail?id=7279
最佳答案
实际上,还有很多其他帖子讨论了人们遇到同样的问题,即 Firefox 启动时屏幕空白,什么也不做。我尝试了从 v25.0.1 到 v33 的所有 Firefox 组合以及从 v2.41.0 到 v2.44.0 的所有版本的 selenium-server-standalone,我唯一可以使用的组合是 FF v25.0.1 和 SSS v2.41.0。/p>
所以我终于想出了一个解决这个问题的方法,这样我就可以使用 FF v33 进行正常冲浪,并让 Selenium 与 FF v25 一起工作。这就是我所做的:
(1) 我将日常使用的 Firefox 更新到了最新版本。
(2) 我从这里下载了第二个旧版本的 Firefox (v25.0.1) https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/25.0.1/然后在我的 Mac 上,我安装到桌面上,然后将其从 Firefox.app 重命名为 Firefox25.0.1.app,然后将其移至我的应用程序文件夹中。
(3) 我从这里为 Firefox 创建了一个新的第二个配置文件 https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles并将其命名为 ffSeleniumProfile
(4) 然后,我必须确保配置文件仍将默认配置文件作为默认配置。在 Mac 上,查看 ~/Library/Application Support/Firefox/profiles.ini
文件,它应该如下所示(请注意,Default=1
应位于 Profile0 下)
[General]
StartWithLastProfile=1
[Profile0]
Name=default
IsRelative=1
Path=Profiles/abcd1234.default
Default=1
[Profile1]
Name=ffSeleniumProfile
IsRelative=1
Path=Profiles/a1b2c3d4.ffSeleniumProfile
(5) 对于 Selenium Server Standalone,请确保您使用的是此处的 v2.41.0 selenium-server-standalone-2.41.0.jar
http://selenium-release.storage.googleapis.com/2.41/selenium-server-standalone-2.41.0.jar
(6) 最后,当您启动 Java 并调用 Firefox/FirefoxDriver 时,您需要指定它使用 Firefox25.0.1.app 和 ffSeleniumProfile。我通过将以下 System.setProperty 添加到启动 java 时使用的主 java 文件的 main 方法来实现此目的:
public static void main(String[] args)
throws InterruptedException,MalformedURLException {
System.setProperty("webdriver.firefox.bin", "/Applications/Firefox25.0.1.app/Contents/MacOS/firefox-bin");
System.setProperty("webdriver.firefox.profile", "ffSeleniumProfile");
}
现在,当我启动 Selenium Java 时,它将使用 v25.0.1 的 Firefox 以及第二个配置文件,当我从桌面启动 Firefox 时,它将使用默认配置文件以及我升级的最新版本。
这只是一个解决方法,但它暂时解决了我的问题。
关于java - Selenium-Standalone-Server 无法在 Firefox 上运行并保持空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23450633/