package org.openqa.selenium.example;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSuggest {
public static void main(String[] args) throws Exception {
// The Firefox driver supports javascript
WebDriver driver = new FirefoxDriver();
// Go to the Google Suggest home page
driver.get("http://www.google.com/webhp?complete=1&hl=en");
// Enter the query string "Cheese"
WebElement query = driver.findElement(By.name("q"));
query.sendKeys("Cheese");
// Sleep until the div we want is visible or 5 seconds is over
long end = System.currentTimeMillis() + 5000;
while (System.currentTimeMillis() < end) {
WebElement resultsDiv = driver.findElement(By.className("gssb_e"));
// If results have been returned, the results are displayed in a drop down.
if (resultsDiv.isDisplayed()) {
break;
}
}
// And now list the suggestions
List<WebElement> allSuggestions = driver.findElements(By.xpath("//td[@class='gssb_a gbqfsf']"));
for (WebElement suggestion : allSuggestions) {
System.out.println(suggestion.getText());
}
driver.quit();
}
}
错误 -
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
419587346786 addons.xpi-utils DEBUG Make addon app-profile:fxdriver@googlecode.com visible
1419587346788 DeferredSave.extensions.json DEBUG Save changes
1419587346788 DeferredSave.extensions.json DEBUG Save changes
1419587346789 addons.xpi DEBUG New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
1419587346793 addons.xpi-utils DEBUG Make addon app-global:{972ce4c6-7e08-4474-a285-3208198ce6fd} visible
1419587346793 DeferredSave.extensions.json DEBUG Save changes
1419587346793 DeferredSave.extensions.json DEBUG Save changes
1419587346793 addons.xpi DEBUG New add-on {D19CA586-DD6C-4a0a-96F8-14644F340D60} installed in winreg-app-global
1419587346803 addons.xpi-utils DEBUG Make addon winreg-app-global:{D19CA586-DD6C-4a0a-96F8-14644F340D60} visible
1419587346803 DeferredSave.extensions.json DEBUG Save changes
1419587346803 DeferredSave.extensions.json DEBUG Save changes
1419587346819 addons.xpi DEBUG Updating database with changes to installed add-ons
1419587346819 addons.xpi-utils DEBUG Updating add-on states
1419587346824 addons.xpi-utils DEBUG Writing add-ons list
1419587346833 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1419587346833 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1419587346834 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1419587346834 addons.manager DEBUG Registering shutdown blocker for PluginProvider
1419587347704 DeferredSave.extensions.json DEBUG Starting timer
1419587347734 addons.manager DEBUG shutdown
1419587347735 addons.manager DEBUG Calling shutdown blocker for XPIProvider
1419587347735 addons.xpi DEBUG shutdown
1419587347735 addons.xpi-utils DEBUG shutdown
1419587347735 addons.manager DEBUG Calling shutdown blocker for LightweightThemeManager
1419587347736 addons.manager DEBUG Calling shutdown blocker for OpenH264Provider
1419587347736 addons.manager DEBUG Calling shutdown blocker for PluginProvider
1419587347738 DeferredSave.extensions.json DEBUG Starting write
1419587348285 DeferredSave.extensions.json DEBUG Write succeeded
1419587348285 addons.xpi-utils DEBUG XPI Database saved, setting schema version preference to 16
1419587348285 addons.xpi DEBUG Notifying XPI shutdown observers
1419587348287 addons.manager DEBUG Async provider shutdown done
1419587348764 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
1419587348765 addons.manager DEBUG Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
1419587348767 addons.xpi DEBUG startup
1419587348768 addons.xpi INFO Mapping {D19CA586-DD6C-4a0a-96F8-14644F340D60} to C:\Program Files\Common Files\McAfee\SystemCore
1419587348768 addons.xpi DEBUG Skipping unavailable install location app-system-local
1419587348769 addons.xpi DEBUG Skipping unavailable install location app-system-share
1419587348769 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}
1419587348770 addons.xpi INFO Mapping fxdriver@googlecode.com to C:\Users\391071\AppData\Local\Temp\anonymous5788014813400759008webdriver-profile\extensions\fxdriver@googlecode.com
1419587348770 addons.xpi DEBUG Ignoring file entry whose name is not a valid add-on ID: C:\Users\391071\AppData\Local\Temp\anonymous5788014813400759008webdriver-profile\extensions\webdriver-staging
1419587348770 addons.xpi DEBUG checkForChanges
1419587348787 addons.xpi DEBUG No changes found
1419587348790 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1419587348790 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1419587348791 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1419587348791 addons.manager DEBUG Registering shutdown blocker for PluginProvider
*** Blocklist::_preloadBlocklistFile: blocklist is disabled
1419587350198 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:197)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)
at org.openqa.selenium.example.GoogleSuggest.main(GoogleSuggest.java:14)
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:
419587346786 addons.xpi-utils DEBUG Make addon app-profile:fxdriver@googlecode.com visible
1419587346788 DeferredSave.extensions.json DEBUG Save changes
1419587346788 DeferredSave.extensions.json DEBUG Save changes
1419587346789 addons.xpi DEBUG New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
1419587346793 addons.xpi-utils DEBUG Make addon app-global:{972ce4c6-7e08-4474-a285-3208198ce6fd} visible
1419587346793 DeferredSave.extensions.json DEBUG Save changes
1419587346793 DeferredSave.extensions.json DEBUG Save changes
1419587346793 addons.xpi DEBUG New add-on {D19CA586-DD6C-4a0a-96F8-14644F340D60} installed in winreg-app-global
1419587346803 addons.xpi-utils DEBUG Make addon winreg-app-global:{D19CA586-DD6C-4a0a-96F8-14644F340D60} visible
1419587346803 DeferredSave.extensions.json DEBUG Save changes
1419587346803 DeferredSave.extensions.json DEBUG Save changes
1419587346819 addons.xpi DEBUG Updating database with changes to installed add-ons
1419587346819 addons.xpi-utils DEBUG Updating add-on states
1419587346824 addons.xpi-utils DEBUG Writing add-ons list
1419587346833 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1419587346833 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1419587346834 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1419587346834 addons.manager DEBUG Registering shutdown blocker for PluginProvider
1419587347704 DeferredSave.extensions.json DEBUG Starting timer
1419587347734 addons.manager DEBUG shutdown
1419587347735 addons.manager DEBUG Calling shutdown blocker for XPIProvider
1419587347735 addons.xpi DEBUG shutdown
1419587347735 addons.xpi-utils DEBUG shutdown
1419587347735 addons.manager DEBUG Calling shutdown blocker for LightweightThemeManager
1419587347736 addons.manager DEBUG Calling shutdown blocker for OpenH264Provider
1419587347736 addons.manager DEBUG Calling shutdown blocker for PluginProvider
1419587347738 DeferredSave.extensions.json DEBUG Starting write
1419587348285 DeferredSave.extensions.json DEBUG Write succeeded
1419587348285 addons.xpi-utils DEBUG XPI Database saved, setting schema version preference to 16
1419587348285 addons.xpi DEBUG Notifying XPI shutdown observers
1419587348287 addons.manager DEBUG Async provider shutdown done
1419587348764 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
1419587348765 addons.manager DEBUG Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
1419587348767 addons.xpi DEBUG startup
1419587348768 addons.xpi INFO Mapping {D19CA586-DD6C-4a0a-96F8-14644F340D60} to C:\Program Files\Common Files\McAfee\SystemCore
1419587348768 addons.xpi DEBUG Skipping unavailable install location app-system-local
1419587348769 addons.xpi DEBUG Skipping unavailable install location app-system-share
1419587348769 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}
1419587348770 addons.xpi INFO Mapping fxdriver@googlecode.com to C:\Users\391071\AppData\Local\Temp\anonymous5788014813400759008webdriver-profile\extensions\fxdriver@googlecode.com
1419587348770 addons.xpi DEBUG Ignoring file entry whose name is not a valid add-on ID: C:\Users\391071\AppData\Local\Temp\anonymous5788014813400759008webdriver-profile\extensions\webdriver-staging
1419587348770 addons.xpi DEBUG checkForChanges
1419587348787 addons.xpi DEBUG No changes found
1419587348790 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1419587348790 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1419587348791 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1419587348791 addons.manager DEBUG Registering shutdown blocker for PluginProvider
*** Blocklist::_preloadBlocklistFile: blocklist is disabled
1419587350198 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'PC217330', ip: '10.230.165.168', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_60'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:130)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:197)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)
at org.openqa.selenium.example.GoogleSuggest.main(GoogleSuggest.java:14)
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:
419587346786 addons.xpi-utils DEBUG Make addon app-profile:fxdriver@googlecode.com visible
1419587346788 DeferredSave.extensions.json DEBUG Save changes
1419587346788 DeferredSave.extensions.json DEBUG Save changes
1419587346789 addons.xpi DEBUG New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
1419587346793 addons.xpi-utils DEBUG Make addon app-global:{972ce4c6-7e08-4474-a285-3208198ce6fd} visible
1419587346793 DeferredSave.extensions.json DEBUG Save changes
1419587346793 DeferredSave.extensions.json DEBUG Save changes
1419587346793 addons.xpi DEBUG New add-on {D19CA586-DD6C-4a0a-96F8-14644F340D60} installed in winreg-app-global
1419587346803 addons.xpi-utils DEBUG Make addon winreg-app-global:{D19CA586-DD6C-4a0a-96F8-14644F340D60} visible
1419587346803 DeferredSave.extensions.json DEBUG Save changes
1419587346803 DeferredSave.extensions.json DEBUG Save changes
1419587346819 addons.xpi DEBUG Updating database with changes to installed add-ons
1419587346819 addons.xpi-utils DEBUG Updating add-on states
1419587346824 addons.xpi-utils DEBUG Writing add-ons list
1419587346833 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1419587346833 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1419587346834 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1419587346834 addons.manager DEBUG Registering shutdown blocker for PluginProvider
1419587347704 DeferredSave.extensions.json DEBUG Starting timer
1419587347734 addons.manager DEBUG shutdown
1419587347735 addons.manager DEBUG Calling shutdown blocker for XPIProvider
1419587347735 addons.xpi DEBUG shutdown
1419587347735 addons.xpi-utils DEBUG shutdown
1419587347735 addons.manager DEBUG Calling shutdown blocker for LightweightThemeManager
1419587347736 addons.manager DEBUG Calling shutdown blocker for OpenH264Provider
1419587347736 addons.manager DEBUG Calling shutdown blocker for PluginProvider
1419587347738 DeferredSave.extensions.json DEBUG Starting write
1419587348285 DeferredSave.extensions.json DEBUG Write succeeded
1419587348285 addons.xpi-utils DEBUG XPI Database saved, setting schema version preference to 16
1419587348285 addons.xpi DEBUG Notifying XPI shutdown observers
1419587348287 addons.manager DEBUG Async provider shutdown done
1419587348764 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
1419587348765 addons.manager DEBUG Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
1419587348767 addons.xpi DEBUG startup
1419587348768 addons.xpi INFO Mapping {D19CA586-DD6C-4a0a-96F8-14644F340D60} to C:\Program Files\Common Files\McAfee\SystemCore
1419587348768 addons.xpi DEBUG Skipping unavailable install location app-system-local
1419587348769 addons.xpi DEBUG Skipping unavailable install location app-system-share
1419587348769 addons.xpi INFO Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}
1419587348770 addons.xpi INFO Mapping fxdriver@googlecode.com to C:\Users\391071\AppData\Local\Temp\anonymous5788014813400759008webdriver-profile\extensions\fxdriver@googlecode.com
1419587348770 addons.xpi DEBUG Ignoring file entry whose name is not a valid add-on ID: C:\Users\391071\AppData\Local\Temp\anonymous5788014813400759008webdriver-profile\extensions\webdriver-staging
1419587348770 addons.xpi DEBUG checkForChanges
1419587348787 addons.xpi DEBUG No changes found
1419587348790 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1419587348790 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1419587348791 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1419587348791 addons.manager DEBUG Registering shutdown blocker for PluginProvider
*** Blocklist::_preloadBlocklistFile: blocklist is disabled
1419587350198 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
... 7 more
答案 0 :(得分:5)
以下是您问题的一些解决方案,请尝试一下。
<强> 1。升级到“selenium-server-standalone-2.44.0”和“selenium-java-2.44.0”。
2尝试以下步骤
A)卸载最新的firefox。
B)安装3.22版本的Firefox。
C)运行您的selenium计划。
Here是各种FF版本的下载链接(确保下载'esr'版本)
第3。建议您在进行测试时关闭FF的自动更新。
以下是我发现的FF和Selenium版本之间报道的一些问题
Selenium版本:2.42&amp; FF 29
Selenium 2.41.0&amp; FF 32.0
Selenium WebDriver版本:2.42。 &安培; FF 32.0
Selenium 2.43.1&amp; FF 31.1.1
Selenium v2.43&amp; FF 27
selenium-firefox-driver 2.44&amp; FF 34.0.5
答案 1 :(得分:1)
升级到最新的Selenium版本,目前版本为2.45.0
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
为所有与selenium相关的依赖项执行此操作。您随时可以查看最新版本here。