![](/img/trans.png)
[英]org.openqa.selenium.remote.UnreachableBrowserException:
[英]org.openqa.selenium.remote.UnreachableBrowserException How to define EXE path?
我在ChromeBrowser包中有這個Java類代碼(我做了)
package ChromeBrowser;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchChrome{
public static void main(String[] args){
String url = "<<<The URL I want to open>>>";
WebDriver driver = setUp();
launch(driver, url);
}
static void launch(WebDriver driver, String url) {
driver.navigate().to(url);
}
static WebDriver setUp() {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
return driver;
}
}
但是當我運行它時,我得到了錯誤:
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.
我已采取的步驟:
預期結果:
我是否需要在C:\\ Program Files(x86)\\ Google \\ Chrome \\ Application下定義chrome可執行文件的路徑?
請幫助我,謝謝。
編輯::我已經嘗試了其他大多數使用錯誤名稱的堆棧溢出問題,但它們並沒有幫助。
我不太確定問題是什么,但是您可以嘗試以下建議-
System.setProperty(“ webdriver.chrome.driver”,“ C:/Selenium/chromedriver.exe”);
這可能是您使用的“硒”,“ Chrome瀏覽器版本”和“ chrome驅動程序”版本之間的兼容性問題。 如果您使用的是Selenium 2.53,則應使用chrome驅動程序2.25。
從seleniumhq.org下載最新的Chrome驅動程序
將127.0.0.1本地主機添加到C:\\ Windows \\ System32 \\ drivers \\ etc \\ hosts。
似乎使用Firefox創建會話存在一些問題。 嘗試以下代碼,然后使用Chrome瀏覽器進行測試。
您需要從以下位置下載可執行驅動程序: https : //sites.google.com/a/chromium.org/chromedriver/downloads
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver",
"/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver = new ChromeDriver();
//Puts an Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch website
driver.get("http://www.calculator.net/");
//Maximize the browser
driver.manage().window().maximize();
或檢查網絡設置(代理,防火牆,防病毒軟件),發現某些東西阻止了硒與瀏覽器之間的連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.