截至2016年9月
在将Firefox与WebDriver一起使用时出现错误。
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms.
有人遇到类似问题或想法吗,对此有什么解决方案?在Chrome上运行正常,但在Firefox上未加载任何URL。
很遗憾,Selenium WebDriver 2.53.0与Firefox 47.0不兼容。处理Firefox浏览器(FirefoxDriver
)的WebDriver组件将停产。从3.0版开始,Selenium WebDriver将需要geckodriver
二进制文件来管理Firefox浏览器。更多信息here和here。
因此,为了将Firefox 47.0用作带有Selenium WebDriver 2.53.0的浏览器,您需要下载Firefox driver(这是一个名为geckodriver
的二进制文件,从0.8.0版本开始,以前是wires
)并将其绝对路径导出为变量webdriver.gecko.driver
作为Java代码中的系统属性:
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
幸运的是,库WebDriverManager可以为您完成这项工作,即为您的计算机(Linux,Mac或Windows)下载正确的Marionette二进制文件并导出正确的系统属性的值。要使用该库,您需要将此依赖项包括到您的项目中:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.7.1</version>
</dependency>
...,然后在使用WebDriver之前在程序中执行此行:
WebDriverManager.firefoxdriver().setup();
使用WebDriver的JUnit 4测试用例的完整运行示例如下:
public class FirefoxTest {
protected WebDriver driver;
@BeforeClass
public static void setupClass() {
WebDriverManager.firefoxdriver().setup();
}
@Before
public void setupTest() {
driver = new FirefoxDriver();
}
@After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
@Test
public void test() {
// Your test code here
}
}
考虑到Marionette将是未来的唯一选择(对于WebDriver 3+和Firefox 48+),但是目前(在撰写本文时为0.9.0版)不是很稳定。请查看Marionette roadmap了解更多详细信息。
UPDATE
Selenium WebDriver 2.53.1已于2016年6月30日发布。FirefoxDriver
再次使用Firefox 47.0.1作为浏览器。
您可以尝试使用此代码,
我最终安装了另一个旧版本的Firefox(仅用于测试)以解决此问题,除了我的常规(安全,最新)最新Firefox安装。
这需要Webdriver知道可以在哪里找到Firefox二进制文件,可以通过webdriver.firefox.bin
属性设置。
对我有用的(mac,maven,/tmp/ff46
作为安装文件夹)是:
mvn -Dwebdriver.firefox.bin=/tmp/ff46/Firefox.app/Contents/MacOS/firefox-bin verify
problem looked like in Wireshar k是什么>
只需加载2.53.1,一切都会正常。
截至2016年9月
[Firefox 48.0
和selenium==2.53.6
正常运行,没有任何错误
要在Ubuntu 14.04
上升级Firefox,[[仅
sudo apt-get update
sudo apt-get upgrade firefox
截至2016年9月
我将Firefox初始化更改为:
string geckoPathTest = Path.Combine(Environment.CurrentDirectory, "TestFiles\\geckodriver.exe");
string geckoPath = Path.Combine(Environment.CurrentDirectory, "geckodriver.exe");
File.Copy(geckoPathTest, geckoPath);
Environment.SetEnvironmentVariable("webdriver.gecko.driver", geckoPath);
_firefoxDriver = new FirefoxDriver();
selenium 2.53.6
与firefox 44
一起使用。尝试使用Firefox 46.0.1。与Selenium 2.53最匹配]
https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64/en-US/
我有相同的问题,发现您需要切换驱动程序,因为support was dropped。代替使用Firefox Driver,您需要使用Marionette驱动程序来运行测试。我目前正在自己进行设置,如果您有我的工作示例,可以发布一些建议的步骤。
以下是我要在Mac上的Java环境上运行该文件的步骤(同样在我的Linux安装(Fedora,CentOS和Ubuntu)中也适用于我:]]
mkdir -p /opt/marionette
)$PATH
以包含可执行文件(也可以根据需要编辑.bash_profile
)chmod +x /opt/marionette/wires-x.x.x
可执行,速记
仍然无法正常工作,但至少现在启动了浏览器。需要弄清楚原因-现在看来我需要重写测试才能使其正常工作。
Java代码段
WebDriver browser = new MarionetteDriver();
System.setProperty("webdriver.gecko.driver", "/opt/marionette/wires-0.7.1-OSX");
如果您使用Homebrew在OSX上,则可以通过brew cask安装旧的Firefox版本:
brew tap goldcaddy77/firefox
brew cask install firefox-46 # or whatever version you want
安装后,您只需要将Applications目录中的FF可执行文件重命名为“ Firefox”。
更多信息可以在git repo homebrew-firefox中找到。支撑smclernon以创建original cask。
如果您使用的是Mac,请执行brew install geckodriver
,然后关闭即可!
如果有人想知道如何在C#中使用木偶。
FirefoxProfile profile = new FirefoxProfile(); // Your custom profile
var service = FirefoxDriverService.CreateDefaultService("DirectoryContainingTheDriver", "geckodriver.exe");
// Set the binary path if you want to launch the release version of Firefox.
service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
var option = new FirefoxProfileOptions(profile) { IsMarionette = true };
var driver = new FirefoxDriver(
service,
option,
TimeSpan.FromSeconds(30));
覆盖FirefoxOptions以提供添加其他功能并设置Firefox配置文件的功能,因为selenium v53尚不提供该功能。
public class FirefoxProfileOptions : FirefoxOptions
{
private DesiredCapabilities _capabilities;
public FirefoxProfileOptions()
: base()
{
_capabilities = DesiredCapabilities.Firefox();
_capabilities.SetCapability("marionette", this.IsMarionette);
}
public FirefoxProfileOptions(FirefoxProfile profile)
: this()
{
_capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());
}
public override void AddAdditionalCapability(string capabilityName, object capabilityValue)
{
_capabilities.SetCapability(capabilityName, capabilityValue);
}
public override ICapabilities ToCapabilities()
{
return _capabilities;
}
}
注意:使用配置文件启动不适用于FF 47,但适用于FF 50 Nightly。
但是,我们试图将测试转换为使用Marionette,但由于驱动程序的实现未完成或有故障,目前暂时不可行。我建议人们此时将其Firefox降级。
根据:https://github.com/SeleniumHQ/selenium/issues/2110,现在已经有新的Selenium库出现了>
下载页面http://www.seleniumhq.org/download/似乎尚未更新,但是通过在链接的次要版本中添加1,我可以下载C#版本:http://selenium-release.storage.googleapis.com/2.53/selenium-dotnet-2.53.1.zip
它对我来说适用于Firefox 47.0.1。
作为旁注,我可以通过运行./go //javascript/firefox-driver:webdriver:run
从GitHub的master分支中仅构建webdriver.xpi
是FF47问题https://github.com/SeleniumHQ/selenium/issues/2110
请降级到FF 46或以下(或试用FF48开发人员https://developer.mozilla.org/en-US/Firefox/Releases/48)
有关降级的说明:https://www.liberiangeek.net/2012/04/how-to-install-previous-versions-of-firefox-in-ubuntu-12-04-precise-pangolin/或者,如果您使用的是Mac,请按照该线程中其他人的建议使用brew。
Firefox 47.0停止使用Webdriver。
最简单的解决方案是切换到Firefox 47.0.1和Webdriver 2.53.1。此组合再次有效。实际上,根据https://www.mozilla.org/en-US/firefox/47.0.1/releasenotes/,恢复Webdriver兼容性是47.0.1版本背后的主要原因。
您可以尝试使用此代码,
private WebDriver driver; System.setProperty("webdriver.firefox.marionette","Your path to driver/geckodriver.exe"); driver = new FirefoxDriver();
我已升级到硒3.0.0,而Firefox版本是49.0.1
您可以从https://github.com/mozilla/geckodriver/releases下载geckodriver.exe
请确保根据您的系统仅下载zip文件,geckodriver-v0.11.1-win64.zip文件或win32,并将其解压缩到文件夹中。
将文件夹的路径放在“您的驱动程序路径”中。不要忘记将geckodriver.exe放在路径中。
我最终安装了另一个旧版本的Firefox(仅用于测试)以解决此问题,除了我的常规(安全,最新)最新Firefox安装。
这需要Webdriver知道可以在哪里找到Firefox二进制文件,可以通过webdriver.firefox.bin
属性设置。
对我有用的(mac,maven,/tmp/ff46
作为安装文件夹)是:
mvn -Dwebdriver.firefox.bin=/tmp/ff46/Firefox.app/Contents/MacOS/firefox-bin verify
要在专用文件夹中安装旧版本的Firefox,请创建该文件夹,在该文件夹中打开Finder,下载Firefox dmg,然后将其拖到该Finder中。
problem looked like in Wireshar k是什么>
只需加载2.53.1,一切都会正常。
截至2016年9月
[Firefox 48.0
和selenium==2.53.6
正常运行,没有任何错误
要在Ubuntu 14.04
上升级Firefox,[[仅
sudo apt-get update
sudo apt-get upgrade firefox
在我看来,最好的解决方案是更新到Selenium 3.0.0,下载geckodriver.exe并使用Firefox 47或更高版本。我将Firefox初始化更改为:
string geckoPathTest = Path.Combine(Environment.CurrentDirectory, "TestFiles\\geckodriver.exe"); string geckoPath = Path.Combine(Environment.CurrentDirectory, "geckodriver.exe"); File.Copy(geckoPathTest, geckoPath); Environment.SetEnvironmentVariable("webdriver.gecko.driver", geckoPath); _firefoxDriver = new FirefoxDriver();
我可以在Ubuntu 15上为我确定selenium 2.53.6
与firefox 44
一起使用。
如果您使用Homebrew在OSX上,则可以通过brew cask安装旧的Firefox版本:
如果您使用的是Mac,请执行brew install geckodriver
,然后关闭即可!
如果有人想知道如何在C#中使用木偶。
根据:https://github.com/SeleniumHQ/selenium/issues/2110,现在已经有新的Selenium库出现了>
下载页面http://www.seleniumhq.org/download/似乎尚未更新,但是通过在链接的次要版本中添加1,我可以下载C#版本:http://selenium-release.storage.googleapis.com/2.53/selenium-dotnet-2.53.1.zip
是FF47问题https://github.com/SeleniumHQ/selenium/issues/2110
请降级到FF 46或以下(或试用FF48开发人员https://developer.mozilla.org/en-US/Firefox/Releases/48)
有关降级的说明:https://www.liberiangeek.net/2012/04/how-to-install-previous-versions-of-firefox-in-ubuntu-12-04-precise-pangolin/或者,如果您使用的是Mac,请按照该线程中其他人的建议使用brew。
Firefox 47.0停止使用Webdriver。
最简单的解决方案是切换到Firefox 47.0.1和Webdriver 2.53.1。此组合再次有效。实际上,根据https://www.mozilla.org/en-US/firefox/47.0.1/releasenotes/,恢复Webdriver兼容性是47.0.1版本背后的主要原因。