我是selenium webdriver的新手,并且使用selenium-server-standalone-2.39.0.jar和Firefox 25.0。
这是我的代码:
package org.cost;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class First_Program {
WebDriver driver;
@BeforeTest
public void beforetest(){
driver= new FirefoxDriver();
System.out.println("testing");
driver.manage().window().maximize();
}
@Test
public void test(){
System.out.println("hello");
driver.get("http://www.rediff.com/");
driver.findElement(By.xpath("//*[@id='signin_info']/a[1]")).click();
driver.findElement(By.xpath("//*[@id='c_uname']")).sendKeys("hello");
}
}
当我运行此代码时,Firefox窗口会启动但在一段时间后我会收到以下错误:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
*** LOG addons.manager: Application has been upgraded
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\User\AppData\Local\Temp\anonymous1906693611994803668webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi-utils: Opening database
*** LOG addons.xpi-utils: Creating database schema
*** LOG addons.xpi: New add-on fxdriver@googlecode.com installed in app-profile
*** LOG addons.xpi: New add-on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} installed in app-global
*** LOG addons.xpi: Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** WARN addons.xpi: Failed to add URI mapping: TypeError: this.enabledAddons.split is not a function (resource://gre/modules/XPIProvider.jsm:1562)
*** LOG addons.xpi: Calling bootstrap method install on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 7.2.15747.10003
*** LOG addons.xpi: New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
*** LOG addons.xpi: New add-on {22C7F6C6-8D67-4534-92B5-529A0EC09405} installed in winreg-app-global
*** LOG addons.xpi: Updating database with changes to installed add-ons
*** LOG addons.xpi-utils: Updating add-on states
*** LOG addons.xpi-utils: Writing add-ons list
*** LOG addons.xpi: Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** LOG addons.xpi: Calling bootstrap method startup on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 7.2.15747.10003
*** LOG addons.manager: shutdown
*** LOG addons.xpi: shutdown
*** LOG addons.xpi-utils: shutdown
*** LOG addons.xpi-utils: Database closed
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\User\AppData\Local\Temp\anonymous1906693611994803668webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found
*** LOG addons.xpi: Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** LOG addons.xpi: Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** LOG addons.xpi: Calling bootstrap method startup on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 7.2.15747.10003
JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:109)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:245)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:109)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:185)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:178)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:174)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
at org.cost.First_Program.beforetest(First_Program.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
FAILED CONFIGURATION: @BeforeTest beforetest
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7055; process output follows:
*** LOG addons.manager: Application has been upgraded
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\User\AppData\Local\Temp\anonymous1906693611994803668webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi-utils: Opening database
*** LOG addons.xpi-utils: Creating database schema
*** LOG addons.xpi: New add-on fxdriver@googlecode.com installed in app-profile
*** LOG addons.xpi: New add-on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} installed in app-global
*** LOG addons.xpi: Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** WARN addons.xpi: Failed to add URI mapping: TypeError: this.enabledAddons.split is not a function (resource://gre/modules/XPIProvider.jsm:1562)
*** LOG addons.xpi: Calling bootstrap method install on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 7.2.15747.10003
*** LOG addons.xpi: New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
*** LOG addons.xpi: New add-on {22C7F6C6-8D67-4534-92B5-529A0EC09405} installed in winreg-app-global
*** LOG addons.xpi: Updating database with changes to installed add-ons
*** LOG addons.xpi-utils: Updating add-on states
*** LOG addons.xpi-utils: Writing add-ons list
*** LOG addons.xpi: Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** LOG addons.xpi: Calling bootstrap method startup on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 7.2.15747.10003
*** LOG addons.manager: shutdown
*** LOG addons.xpi: shutdown
*** LOG addons.xpi-utils: shutdown
*** LOG addons.xpi-utils: Database closed
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\User\AppData\Local\Temp\anonymous1906693611994803668webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found
*** LOG addons.xpi: Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** LOG addons.xpi: Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** LOG addons.xpi: Calling bootstrap method startup on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 7.2.15747.10003
JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_21'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:121)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:245)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:109)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:185)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:178)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:174)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
at org.cost.First_Program.beforetest(First_Program.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
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:
*** LOG addons.manager: Application has been upgraded
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\User\AppData\Local\Temp\anonymous1906693611994803668webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi-utils: Opening database
*** LOG addons.xpi-utils: Creating database schema
*** LOG addons.xpi: New add-on fxdriver@googlecode.com installed in app-profile
*** LOG addons.xpi: New add-on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} installed in app-global
*** LOG addons.xpi: Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** WARN addons.xpi: Failed to add URI mapping: TypeError: this.enabledAddons.split is not a function (resource://gre/modules/XPIProvider.jsm:1562)
*** LOG addons.xpi: Calling bootstrap method install on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 7.2.15747.10003
*** LOG addons.xpi: New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
*** LOG addons.xpi: New add-on {22C7F6C6-8D67-4534-92B5-529A0EC09405} installed in winreg-app-global
*** LOG addons.xpi: Updating database with changes to installed add-ons
*** LOG addons.xpi-utils: Updating add-on states
*** LOG addons.xpi-utils: Writing add-ons list
*** LOG addons.xpi: Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** LOG addons.xpi: Calling bootstrap method startup on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 7.2.15747.10003
*** LOG addons.manager: shutdown
*** LOG addons.xpi: shutdown
*** LOG addons.xpi-utils: shutdown
*** LOG addons.xpi-utils: Database closed
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\User\AppData\Local\Temp\anonymous1906693611994803668webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found
*** LOG addons.xpi: Registering manifest for C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** LOG addons.xpi: Loading bootstrap scope from C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{82AF8DCA-6DE9-405D-BD5E-43525BDAD38A}.xpi
*** LOG addons.xpi: Calling bootstrap method startup on {82AF8DCA-6DE9-405D-BD5E-43525BDAD38A} version 7.2.15747.10003
JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:109)
... 29 more
SKIPPED: test
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@22c6bb6c: 158 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@12a312c6: 262 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@5b390546: 36 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 22 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@74e0e49f: 91 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@41ce5a9: 16 ms
请建议我,我在这里做错了什么?
由于
答案 0 :(得分:0)
请将您的selenium独立jar文件更新到最新的甚至是firefox浏览器,然后尝试运行该脚本。
Selenium独立2.41x或2.42x firefox ...首先尝试使用您的版本,如果您仍然遇到问题,请尝试升级到最新版本。
谢谢,
Shravan Kumar.T
答案 1 :(得分:0)
这是更改日志,它将帮助您选择firefox版本(适用于Java)
https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG
我希望最新的standalone jar,firefox 39没有任何问题。在我的工作空间中,我根据要求使用FF 31和最新的jar。我没有像这样的任何连接问题..
谢谢