2014-03-04 33 views
1

的一段代碼是:獲得一個UnreachableBrowserException同時使用ChromeDriver

另一個編輯:想請注意,我用java實現這個,所以我不認爲斜線將是一個問題。 (雖然糾正我,如果我錯了)

編輯:還有一點我想補充的是,它實際上說,它的啓動鉻驅動程序版本的東西,但立即出現故障時

System.setProperty("webdriver.chrome.driver", "webdrivers/chromedriver.exe"); 
     driver = new ChromeDriver(); 

後和我最終會得到的錯誤是

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: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:15:02' 
System info: host: '****-PC', ip: '10.10.10.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_51' 

沒有堆棧跟蹤,這發生在webdriver嘗試啓動後立即發生。我猜測上面的代碼是它發生的地方,因爲netbeans並沒有真正指出它出錯的地方。

神祕的是,這在我的電腦上工作,但試圖在同事的電腦上運行它只是產生這個錯誤。 Firefox適用於她,但IE和Chrome都是這樣。有任何想法嗎?

編輯:顯然有一個堆棧跟蹤:

Driver info: driver.version: ChromeDriver 
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165) 
at  org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62) 
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527) 
... 7 more 
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for  [http://localhost:8891/status] to be available after 20002 ms 
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104) 
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163) 
... 9 more 
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException 
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143) 
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79) 
... 10 more 
Caused by: java.util.concurrent.TimeoutException 
at java.util.concurrent.FutureTask.get(FutureTask.java:201) 
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130) 
... 11 more 
+0

當dbl單擊它時直接執行chromedriver.exe會發生什麼情況?你有什麼錯誤呢? – Faiz

+0

它只是說在cmd窗口中啓動驅動程序。沒有別的之後 – axidus1989

回答

0

webdrivers/chromedriver.exe

我懷疑它找不到chromedriver。你確定這是通往chromedriver.exe的正確道路嗎?

你應該嘗試絕對路徑。

例如C:/Users/Name/Desktop/webdrivers/chromedriver.exe

+0

是的,我的同事嘗試了絕對路徑,它仍然不神祕。但通常如果我給它一個錯誤的路徑,它會給我一個不同的例外,如「.exe不可用」。 – axidus1989

+0

axidus1989,您是否嘗試雙斜槓//而不是單斜槓/在Amith提到的chromdriver的路徑中?我認爲這應該工作。 – TDHM

+0

我正在使用java將\翻譯成\\在Windows中,所以它不應該是什麼導致的問題,但我會問我的同事試一試 – axidus1989

0
  1. 確保您正在使用最新的Chrome瀏覽器背後的一個版本,並
  2. 最新Chromedriver.exe版本2.9
  3. 路徑應該像C://Test//chromedriver.exe
  4. 被提及
+0

剛剛意識到她沒有使用最新版本。我會留下她的筆記,看看這是否能解決這個問題 – axidus1989

1

您或者需要添加絕對路徑在Win dows可能需要包含逃逸的反斜槓,例如

System.setProperty("webdriver.chrome.driver", "C:\\chromedriver\\chromedriver.exe"); 
driver = new ChromeDriver(); 

或者您可以將屬性添加到您的系統路徑。

如果這些選項不起作用,可能是連接到ChromeDriver時出現問題。在這種情況下,你可以打開該文件Chromedriver.exe

WebDriver driver = new RemoteWebDriver("http://localhost:9515", DesiredCapabilities.chrome()); 
driver.get("http://www.google.com"); 

https://code.google.com/p/selenium/wiki/ChromeDriver

0

當我使用絕對路徑,這是給我的錯誤。但是,當我使用可執行文件所在的目錄時,它啓動得很好。這裏是一個C#示例

using OpenQA.Selenium.Chrome; 

public class ChromeOptionsWithPrefs : ChromeOptions 
{ 
    public Dictionary<string, object> prefs { get; set; } 
} 

public static void Start() 
{ 
    var options = new ChromeOptionsWithPrefs(); 
    options.AddArguement("-incognito"); 
    using (IWebDriver driver = new ChromeDriver(@"C:\FilePath\", options)) 
    { 
     //perform the test 
     driver.Navigate().GoToURL(@"http://www.google.com"); 
     driver.Quit(); 
    } 
} 

我只是使用首選項不存儲任何上機我上運行測試的任何數據。這不是必需的,但你可以通過一些有趣的選項。

+0

我使用Java來編寫代碼,所以在表面嘗試了這個之後,它給了我一個錯誤,那就是可執行文件是一個目錄,因此我認爲它不起作用。 – axidus1989

相關問題