无法使用Selenium打开Chrome驱动程序

时间:2014-02-25 05:06:52

标签: selenium

尝试使用以下代码打开Chrome驱动程序时,我遇到异常。

Chrome窗口会自动打开和关闭。 我的Chrome版本为:12.0.712.0和Chrome驱动程序版本26.0.1383.0

我使用的代码是:

System.setProperty("webdriver.chrome.driver","F:\\chromedriver.exe");
ChromeDriver cd = new ChromeDriver();
cd.get("http://www.gmail.com");



tarted ChromeDriver
port=10298
version=26.0.1383.0
log=F:\Selnium\Module11\chromedriver.log
Exception in thread "main" org.openqa.selenium.WebDriverException: Unknown command. Options: ActivateTab, CloseTab, DeleteCookie, ExecuteJavascript, GetCookies, GetIndicesFromTab, GetTabIds, GetTabTitle, GetTabURL, GoBack, GoForward, IsTabIdValid, NavigateToURL, Reload, SendWebkitKeyEvent, SetCookie, WaitForAllTabsToStopLoading, WebkitMouseClick, WebkitMouseDrag, WebkitMouseMove, AddHistoryItem, AddOrEditSearchEngine, AddSavedPassword, AwaitSyncCycleCompletion, ClearBrowsingData, CloseNotification, DisablePlugin, DisableSyncForDatatypes, EnablePlugin, EnableSyncForDatatypes, FillAutofillProfile, FindInPage, GetActiveNotifications, GetAutofillProfile, GetBlockedPopupsInfo, GetBrowserInfo, GetDownloadsInfo, GetExtensionsInfo, GetHistoryInfo, GetInitialLoadTimes, GetInstantInfo, GetNTPInfo, GetNTPMenuMode, GetNTPThumbnailMode, GetNavigationInfo, GetOmniboxInfo, GetPluginsInfo, GetPrefsInfo, GetSavedPasswords, GetSearchEngineInfo, GetSyncInfo, GetThemeInfo, GetTranslateInfo, ImportSettings, KillRendererProcess, LoadSearchEngineInfo, MoveNTPMostVisitedThumbnail, OmniboxAcceptInput, OmniboxMovePopupSelection, PerformActionOnDownload, PerformActionOnInfobar, PerformActionOnSearchEngine, RemoveNTPMostVisitedThumbnail, RemoveSavedPassword, RestoreAllNTPMostVisitedThumbnails, SaveTabContents, SelectTranslateOption, SetNTPMenuMode, SetNTPThumbnailMode, SetOmniboxText, SetPrefs, SetWindowDimensions, SignInToSync, UnblockAndLaunchBlockedPopup, UninstallExtensionById, UnpinNTPMostVisitedThumbnail, WaitForAllDownloadsToComplete, WaitForNotificationCount,  (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.65 seconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'ANKUR-PC', ip: '169.254.81.96', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_40'
Driver info: org.openqa.selenium.chrome.ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.chrome.ChromeDriver.startSession(ChromeDriver.java:182)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(`enter code here`RemoteWebDriver.java:115)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:161)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:150)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
    at Selenium.main(Selenium.java:39)

3 个答案:

答案 0 :(得分:0)

使用 -

1 | Chrome 25 + 版本;

2 | 最新的Chrome驱动程序

http://chromedriver.storage.googleapis.com/index.html?path=2.9/

答案 1 :(得分:0)

我和Fire Fox和Chrome有同样的问题?使用通用的HtmlUnitDriver。不需要FireFox或任何其他浏览器。

import org.openqa.selenium.htmlunit.HtmlUnitDriver;
htmldriver = new HtmlUnitDriver();
public class DemoTest {
WebDriver htmldriver;
public void setup() {
htmldriver.get("http://www.seleniumframework.com/demo-sites/");
}
}

答案 2 :(得分:-1)

我也遇到了同样的问题。我刚用最新的谷歌浏览器驱动程序替换了现有的chrome驱动程序。它工作得很好。