Selenium项目不会连接到Firefox



错误:

org.openqa.selenium.firefox.NotConnectedException:无法连接45000毫秒后在端口7055上托管127.0.0.1。Firefox控制台输出:ons.xpi DEBUG调用上的引导程序方法启动onboarding@mozilla.org版本1.01531840048588插件.xpi调试正在为注册清单/Applications/Firefox.app/Contents/Resources/browser/features/screenshots@mozilla.org.xpi1531840048589 addons.xpi DEBUG调用上的引导程序方法启动screenshots@mozilla.org32.1.0版1531840048589 addons.xpi调试正在为注册清单/Applications/Firefox.app/Contents/Resources/browser/features/webcompat-reporter@mozilla.org.xpi1531840048589 addons.xpi DEBUG调用上的引导程序方法启动webcompat-reporter@mozilla.org1.0.0版本1531840048590 addons.xpi调试正在为注册清单/Applications/Firefox.app/Contents/Resources/browser/features/webcompat@mozilla.org.xpi1531840048591 addons.xpi DEBUG调用上的引导程序方法启动webcompat@mozilla.org2.0版1531840048594 addons.manager调试正在为注册关闭阻止程序XPIProvider 1531840048594 addons.manager DEBUG Provider已完成startup:XPIProvider 1531840048594 addons.manager调试启动提供者:LightweightThemeManager1531840048594 addons.manager调试正在为注册关闭阻止程序LightweightThemeManager 1531840048594 addons.manager DEBUG Provider完成启动:LightweightThemeManager1531840048594 addons.manager DEBUG启动提供程序:GMPProvider1531840048596 addons.manager调试正在为注册关闭阻止程序GMP提供程序1531840048596个插件。管理员调试提供程序已完成启动:GMPProvider 1531840048597 addons.manager DEBUG启动provider:PluginProvider1531840048597 addons.manager调试正在为注册关闭阻止程序PluginProvider 1531840048597插件。管理员调试提供程序已完成启动:PluginProvider 1531840048598 addons.manager DEBUG已完成启动序列1531840049193 addons.repository DEBUG No addons.json建立2018-07-17 11:07:29.783插件容器[35125:1788379]*CFMessage端口:bootstrap_register():失败1100(0x44c)'权限拒绝',端口=0x7127,名称='com.apple.tsm.portname'请参阅/usr/include/servers/bootstrap_defs.h获取错误代码。1531840050170 addons.xpi DEBUG忽略名称不是有效的加载项ID:/var/folders/tl/89639tt516lfcbvtl60jn9d80000gq/T/anymous360919038492988020网络驱动程序配置文件/扩展/网络驱动程序暂存1531840050171插件.xpi调试现有插件activity-stream@mozilla.org应用内系统默认值1531840050171插件.xpi调试现有插件aushelper@mozilla.org应用内系统默认1531840050172插件.xpi调试现有插件firefox@getpocket.com应用内系统默认值1531840050172插件.xpi调试现有插件followonsearch@mozilla.com应用内系统默认值1531840050172插件.xpi调试现有插件formautofill@mozilla.org应用内系统默认值1531840050173插件.xpi调试现有插件onboarding@mozilla.org应用内系统默认1531840050173插件.xpi调试现有插件screenshots@mozilla.org应用内系统默认值1531840050174插件.xpi调试现有插件webcompat-reporter@mozilla.org应用内系统默认值1531840050175插件.xpi调试现有插件webcompat@mozilla.org应用内系统默认1531840050176插件.xpi调试忽略文件名称不是有效加载项ID:/Library/Application的条目支持/Mozilla/Extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/.DC1531840050176插件.xpi调试现有插件web2pdfextension.17@acrobat.adobe.com本地应用系统1531840050176 addons.xpi DEBUG getInstallState已更改:false,状态:{}2018-07-17 11:07:30.178插件容器[35126:1788400]*CFMessage端口:bootstrap_register():失败1100(0x44c)'权限拒绝',端口=0x8b43,名称='com.apple.tsm.portname'请参阅/usr/include/servers/bootstrap_defs.h获取错误代码。JavaScript错误:resource://gre/modules/addons/XPIProvider.jsm,第2189行:TypeError:插件为空2018-07-17 11:07:30.872插件容器[35127:1788513]***CFMessage端口:bootstrap_register():失败1100(0x44c)"权限被拒绝",端口=0x6603,name='com.apple.tsm.portname'请参阅/usr/include/servers/bootstrap_defs.h获取错误代码。

at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:112)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at com.ctm.selenium.framework.selenium.browsers.FirefoxBrowser.setWebDriver(FirefoxBrowser.java:19)
at com.ctm.selenium.framework.selenium.browsers.Browser.<init>(Browser.java:48)
at com.ctm.selenium.framework.selenium.browsers.FirefoxBrowser.<init>(FirefoxBrowser.java:8)
at com.ctm.selenium.framework.selenium.browsers.BrowserFactory.getFirefoxBrowser(BrowserFactory.java:109)
at com.ctm.selenium.framework.selenium.browsers.BrowserFactory.getBrowser(BrowserFactory.java:89)
at com.ctm.selenium.framework.verification.junit.TestScript.setupTest(TestScript.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)

在java.lang.Thread.run(线程.java:745)

我该怎么解决这个问题?请尽可能详细,因为我是硒的新手。。。

请尝试下面列出的方法来调用驱动程序。
private WebDriver firefoxDriver;
private void initiateWebDriver() throws  Exception {
System.setProperty("webdriver.gecko.driver", "E:\PATH);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
firefoxDriver = new FirefoxDriver(capabilities);
firefoxDriver.get("https://www.Desired_URL.com");
}

public WebDriver getWebDriver()  throws  Exception{
if (null != firefoxDriver) {
return firefoxDriver;
}
initiateWebDriver();
return firefoxDriver;
}

您可能会因为使用较旧版本的gecko驱动程序或在启动之前没有定义gecko驱动器的预先请求的属性而面临此问题。

System.setProperty("webdriver.gecko.driver", "E:\PATH);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
firefoxDriver = new FirefoxDriver(capabilities);

使用方法getWebDriver()将web驱动程序返回到您喜欢的测试类。

最新更新