我正在尝试使用selenium java代码打开firefox浏览器。
System.setProperty("webdriver.gecko.driver", " System.setProperty("webdriver.gecko.driver", "C:/Program Files/Mozilla Firefox/geckodriver-v0.8.0-win32/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
System.setProperty("webdriver.firefox.port","4444");
Selenium服务器已启动并正在运行。我尝试使用命令提示符更改selenium服务器端口并在代码中设置端口,但它们都不起作用。
> Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700'
System info: host: 'W0045395', ip: '10.17.208.124', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_101'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:670)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:232)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:220)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:215)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:124)
at newpackage.Gmail_Login.main(Gmail_Login.java:18)
Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:6544 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700'
System info: host: 'W0045395', ip: '10.17.208.124', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_101'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:649)
... 8 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:6544 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:142)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:88)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
... 9 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
... 22 more
在错误消息“Connect to localhost:6544”中,它尝试每次都连接到不同的localhost。谁能看到问题所在?
我正在使用的版本是:
此外我的geckodriver可执行文件没有运行,它说VCRUNTIME140.dill丢失了,我应该重新安装来修复问题。但在重新安装之后,同样的事情发生了。
更新
感谢@ Saurabh的建议,我将我的硒降级为2.53.1。浏览器现在正在打开,但没有任何显示。我又收到了一个错误
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
ateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{},"iconURL":"chrome://web2pdfextension/skin/C_AdobeLogo_48x48.png","icon64URL":"chrome://web2pdfextension/skin/C_AdobeLogo_64x64.png","defaultLocale":{"name":"Adobe Acrobat DC - Create PDF","description":"Converts a web page to PDF","creator":"Adobe Systems Incorporated","homepageURL":"http://www.adobe.com/"},"visible":true,"active":false,"userDisabled":true,"appDisabled":false,"descriptor":"C:\\Program Files\\Adobe\\Acrobat DC\\Acrobat\\Browser\\WCFirefoxExtn","installDate":1463491629403,"updateDate":1463491629403,"applyBackgroundUpdates":1,"bootstrap":false,"skinnable":false,"size":345393,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":true,"hasBinaryComponents":false,"strictCompatibility":false,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"4.0","maxVersion":"46.0"}],"targetPlatforms":[],"multiprocessCompatible":false,"signedState":2,"seen":true}
1471356838157 DeferredSave.extensions.json DEBUG Save changes
1471356838157 addons.xpi DEBUG Updating database with changes to installed add-ons
1471356838157 addons.xpi-utils DEBUG Updating add-on states
1471356838158 addons.xpi-utils DEBUG Writing add-ons list
1471356838161 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\e10srollout@mozilla.org.xpi
1471356838162 addons.xpi DEBUG Calling bootstrap method startup on e10srollout@mozilla.org version 1.0
1471356838162 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\firefox@getpocket.com.xpi
1471356838162 addons.xpi DEBUG Calling bootstrap method startup on firefox@getpocket.com version 1.0.4
1471356838163 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\loop@mozilla.org.xpi
1471356838164 addons.xpi DEBUG Calling bootstrap method startup on loop@mozilla.org version 1.4.3
1471356838181 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1471356838181 addons.manager DEBUG Provider finished startup: XPIProvider
1471356838181 addons.manager DEBUG Starting provider: LightweightThemeManager
1471356838181 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1471356838181 addons.manager DEBUG Provider finished startup: LightweightThemeManager
1471356838182 addons.manager DEBUG Starting provider: GMPProvider
1471356838187 addons.manager DEBUG Registering shutdown blocker for GMPProvider
1471356838187 addons.manager DEBUG Provider finished startup: GMPProvider
1471356838187 addons.manager DEBUG Starting provider: PluginProvider
1471356838187 addons.manager DEBUG Registering shutdown blocker for PluginProvider
1471356838187 addons.manager DEBUG Provider finished startup: PluginProvider
1471356838188 addons.manager DEBUG Completed startup sequence
1471356839788 addons.manager DEBUG Starting provider: <unnamed-provider>
1471356839788 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
1471356839788 addons.manager DEBUG Provider finished startup: <unnamed-provider>
1471356840362 DeferredSave.extensions.json DEBUG Write succeeded
1471356840362 addons.xpi-utils DEBUG XPI Database saved, setting schema version preference to 17
1471356840362 DeferredSave.extensions.json DEBUG Starting timer
1471356840374 addons.repository DEBUG No addons.json found.
1471356840374 DeferredSave.addons.json DEBUG Save changes
1471356840377 DeferredSave.addons.json DEBUG Starting timer
1471356840413 addons.manager DEBUG Starting provider: PreviousExperimentProvider
1471356840413 addons.manager DEBUG Registering shutdown blocker for PreviousExperimentProvider
1471356840413 addons.manager DEBUG Provider finished startup: PreviousExperimentProvider
1471356840421 DeferredSave.extensions.json DEBUG Starting write
1471356840440 DeferredSave.addons.json DEBUG Starting write
1471356840460 DeferredSave.extensions.json DEBUG Write succeeded
1471356840495 DeferredSave.addons.json DEBUG Write succeeded
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:129)
at newpackage.Gmail_Login.main(Gmail_Login.java:25)
Exception in thread "main" org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055; process output follows:
ateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{},"iconURL":"chrome://web2pdfextension/skin/C_AdobeLogo_48x48.png","icon64URL":"chrome://web2pdfextension/skin/C_AdobeLogo_64x64.png","defaultLocale":{"name":"Adobe Acrobat DC - Create PDF","description":"Converts a web page to PDF","creator":"Adobe Systems Incorporated","homepageURL":"http://www.adobe.com/"},"visible":true,"active":false,"userDisabled":true,"appDisabled":false,"descriptor":"C:\\Program Files\\Adobe\\Acrobat DC\\Acrobat\\Browser\\WCFirefoxExtn","installDate":1463491629403,"updateDate":1463491629403,"applyBackgroundUpdates":1,"bootstrap":false,"skinnable":false,"size":345393,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":true,"hasBinaryComponents":false,"strictCompatibility":false,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"4.0","maxVersion":"46.0"}],"targetPlatforms":[],"multiprocessCompatible":false,"signedState":2,"seen":true}
1471356838157 DeferredSave.extensions.json DEBUG Save changes
1471356838157 addons.xpi DEBUG Updating database with changes to installed add-ons
1471356838157 addons.xpi-utils DEBUG Updating add-on states
1471356838158 addons.xpi-utils DEBUG Writing add-ons list
1471356838161 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\e10srollout@mozilla.org.xpi
1471356838162 addons.xpi DEBUG Calling bootstrap method startup on e10srollout@mozilla.org version 1.0
1471356838162 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\firefox@getpocket.com.xpi
1471356838162 addons.xpi DEBUG Calling bootstrap method startup on firefox@getpocket.com version 1.0.4
1471356838163 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\loop@mozilla.org.xpi
1471356838164 addons.xpi DEBUG Calling bootstrap method startup on loop@mozilla.org version 1.4.3
1471356838181 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1471356838181 addons.manager DEBUG Provider finished startup: XPIProvider
1471356838181 addons.manager DEBUG Starting provider: LightweightThemeManager
1471356838181 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1471356838181 addons.manager DEBUG Provider finished startup: LightweightThemeManager
1471356838182 addons.manager DEBUG Starting provider: GMPProvider
1471356838187 addons.manager DEBUG Registering shutdown blocker for GMPProvider
1471356838187 addons.manager DEBUG Provider finished startup: GMPProvider
1471356838187 addons.manager DEBUG Starting provider: PluginProvider
1471356838187 addons.manager DEBUG Registering shutdown blocker for PluginProvider
1471356838187 addons.manager DEBUG Provider finished startup: PluginProvider
1471356838188 addons.manager DEBUG Completed startup sequence
1471356839788 addons.manager DEBUG Starting provider: <unnamed-provider>
1471356839788 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
1471356839788 addons.manager DEBUG Provider finished startup: <unnamed-provider>
1471356840362 DeferredSave.extensions.json DEBUG Write succeeded
1471356840362 addons.xpi-utils DEBUG XPI Database saved, setting schema version preference to 17
1471356840362 DeferredSave.extensions.json DEBUG Starting timer
1471356840374 addons.repository DEBUG No addons.json found.
1471356840374 DeferredSave.addons.json DEBUG Save changes
1471356840377 DeferredSave.addons.json DEBUG Starting timer
1471356840413 addons.manager DEBUG Starting provider: PreviousExperimentProvider
1471356840413 addons.manager DEBUG Registering shutdown blocker for PreviousExperimentProvider
1471356840413 addons.manager DEBUG Provider finished startup: PreviousExperimentProvider
1471356840421 DeferredSave.extensions.json DEBUG Starting write
1471356840440 DeferredSave.addons.json DEBUG Starting write
1471356840460 DeferredSave.extensions.json DEBUG Write succeeded
1471356840495 DeferredSave.addons.json DEBUG Write succeeded
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:09'
System info: host: 'W0045395', ip: '10.17.208.124', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_101'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:124)
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:129)
at newpackage.Gmail_Login.main(Gmail_Login.java:25)
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
ateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{},"iconURL":"chrome://web2pdfextension/skin/C_AdobeLogo_48x48.png","icon64URL":"chrome://web2pdfextension/skin/C_AdobeLogo_64x64.png","defaultLocale":{"name":"Adobe Acrobat DC - Create PDF","description":"Converts a web page to PDF","creator":"Adobe Systems Incorporated","homepageURL":"http://www.adobe.com/"},"visible":true,"active":false,"userDisabled":true,"appDisabled":false,"descriptor":"C:\\Program Files\\Adobe\\Acrobat DC\\Acrobat\\Browser\\WCFirefoxExtn","installDate":1463491629403,"updateDate":1463491629403,"applyBackgroundUpdates":1,"bootstrap":false,"skinnable":false,"size":345393,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":true,"hasBinaryComponents":false,"strictCompatibility":false,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"4.0","maxVersion":"46.0"}],"targetPlatforms":[],"multiprocessCompatible":false,"signedState":2,"seen":true}
1471356838157 DeferredSave.extensions.json DEBUG Save changes
1471356838157 addons.xpi DEBUG Updating database with changes to installed add-ons
1471356838157 addons.xpi-utils DEBUG Updating add-on states
1471356838158 addons.xpi-utils DEBUG Writing add-ons list
1471356838161 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\e10srollout@mozilla.org.xpi
1471356838162 addons.xpi DEBUG Calling bootstrap method startup on e10srollout@mozilla.org version 1.0
1471356838162 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\firefox@getpocket.com.xpi
1471356838162 addons.xpi DEBUG Calling bootstrap method startup on firefox@getpocket.com version 1.0.4
1471356838163 addons.xpi DEBUG Registering manifest for C:\Program Files\Mozilla Firefox\browser\features\loop@mozilla.org.xpi
1471356838164 addons.xpi DEBUG Calling bootstrap method startup on loop@mozilla.org version 1.4.3
1471356838181 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1471356838181 addons.manager DEBUG Provider finished startup: XPIProvider
1471356838181 addons.manager DEBUG Starting provider: LightweightThemeManager
1471356838181 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1471356838181 addons.manager DEBUG Provider finished startup: LightweightThemeManager
1471356838182 addons.manager DEBUG Starting provider: GMPProvider
1471356838187 addons.manager DEBUG Registering shutdown blocker for GMPProvider
1471356838187 addons.manager DEBUG Provider finished startup: GMPProvider
1471356838187 addons.manager DEBUG Starting provider: PluginProvider
1471356838187 addons.manager DEBUG Registering shutdown blocker for PluginProvider
1471356838187 addons.manager DEBUG Provider finished startup: PluginProvider
1471356838188 addons.manager DEBUG Completed startup sequence
1471356839788 addons.manager DEBUG Starting provider: <unnamed-provider>
1471356839788 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
1471356839788 addons.manager DEBUG Provider finished startup: <unnamed-provider>
1471356840362 DeferredSave.extensions.json DEBUG Write succeeded
1471356840362 addons.xpi-utils DEBUG XPI Database saved, setting schema version preference to 17
1471356840362 DeferredSave.extensions.json DEBUG Starting timer
1471356840374 addons.repository DEBUG No addons.json found.
1471356840374 DeferredSave.addons.json DEBUG Save changes
1471356840377 DeferredSave.addons.json DEBUG Starting timer
1471356840413 addons.manager DEBUG Starting provider: PreviousExperimentProvider
1471356840413 addons.manager DEBUG Registering shutdown blocker for PreviousExperimentProvider
1471356840413 addons.manager DEBUG Provider finished startup: PreviousExperimentProvider
1471356840421 DeferredSave.extensions.json DEBUG Starting write
1471356840440 DeferredSave.addons.json DEBUG Starting write
1471356840460 DeferredSave.extensions.json DEBUG Write succeeded
1471356840495 DeferredSave.addons.json DEBUG Write succeeded
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:112)
... 6 more
答案 0 :(得分:1)
您需要将具有DesiredCapabilities
功能的marionette
传递给true
以及FirefoxDriver
以及以下: -
System.setProperty("webdriver.gecko.driver", "C:/Program Files/Mozilla Firefox/geckodriver-v0.8.0-win32/geckodriver.exe");
//Now you can Initialize marionette driver to launch firefox
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
已修改:如果不幸上述不起作用,我建议您将您的Firefox降级到45或更低并使用FirefoxDriver
,如下所示: - < / p>
WebDriver driver = new FirefoxDriver();
答案 1 :(得分:0)
首先确保添加了所有jar文件,包括来自/ lib文件夹的以下代码片段代码将打开带有添加http链接的浏览器。顺便说一下,我用的是win7 64bit,所以要注意geckodrive路径。
System.setProperty("webdriver.gecko.driver", "C:\\Users\\XYZ\\Documents\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
try {
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://google.com");
} catch(Exception e) {
System.out.println(e);
}