2016-05-18 264 views
0

使用下面的代碼嘗試訪問google chrome便攜式瀏覽器。無法使用Selenium打開Goog​​le Chrome Portable

System.setProperty("webdriver.chrome.driver","C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChromePortable.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. 

誰能幫助我如何與硒的webdriver訪問谷歌的Chrome瀏覽器移植。

+0

司機的.exe會像chromedriver.exe – theRoot

回答

1

下面的代碼成功調用了Google chrome便攜式瀏覽器。

ChromeOptions options = new ChromeOptions(); 
    options.setBinary("C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChromePortable.exe"); 
    System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\Browsers\\chromedriver.exe");    
    driver = new ChromeDriver(options); 
+0

太好了。需要添加該設置屬性。這是一個很好的問題Aparna。 –

0

使用Chromedriver.exe來在Chrome瀏覽器上運行測試用例。

String ChromeDriverPath= "path\\chromedriver.exe"; 
System.setProperty("webdriver.chrome.driver", ChromeDriverPath); 
WebDriver driver=new ChromeDriver(); 

Chromedriver exe文件可在

http://www.seleniumhq.org/download/

只需提取它,並給Chromedriver.exe

的路徑

做一兩件事:

Public class processclass{ 
    Process getBrowserProcess() { 
     Process p = null; 
     try { 
      p = Runtime.getRuntime() 
        .exec("C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChrom‌​ePortable.exe"); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return p; 
    } 

} 

而另一個類將包含你的測試用例。 因此,創建上面的類的對象,讓我們說:

processclass Object = new processclass(); 

Object.getBrowserProcess(); 

然後運行驅動程序的命令。

希望這對你有所幫助..

+0

感謝您的答覆,我可以用chromedriver.exe訪問本地安裝了Chrome瀏覽器,但需要調用的Chrome瀏覽器便攜。而exe文件是'GoogleChromePortable.exe',我的要求是用selenium webdriver訪問這個exe文件。 – SeJaPy

+0

好的。 :-) 試試這個 ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setBinary(binaryPath); driver = new ChromeDriver(chromeOptions); –

+0

再次感謝,如果我沒有錯,這是「C:\\ Selenium \\ Browsers \\ GoogleChromePortable \\ GoogleChromePortable.exe」二進制路徑嗎? – SeJaPy

相關問題