2015-09-28 76 views
5

我有一個Selenium網絡驅動程序的問題。我想要做的是啓動一個「便攜式」鉻代替我的本地安裝,因爲它有不同的設置。硒不啓動便攜式鉻但本地安裝

問題是便攜式Chrome(來自PortableApps)似乎只在使用GoogleChromePortable.exe時纔會啓動。如果我直接使用Chrome二進制文件,它將啓動我的本地安裝。 對於Selenium,似乎無論我將哪個Chrome路徑傳遞給它(GoogleChromePortable.exe或二進制路徑),它都會啓動本地安裝。

這裏是我的代碼:

String chromePath = "M:/my/path"; 
DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
ChromeOptions options = new ChromeOptions(); 
capabilities.setCapability("chrome.binary", chromePath); 
capabilities.setCapability(ChromeOptions.CAPABILITY, options); 

任何想法如何能夠啓動我的便攜鉻? 謝謝

回答

2

爲別人絆倒在這個問題,這是我如何設法使便攜式Chrome的起點:

ChromeOptions chromeOptions = new ChromeOptions(); 
chromeOptions.setBinary(binaryPath); 
driver = new ChromeDriver(chromeOptions); 
0

根據你在ChromePortable中的設置,也許你可以默認ChromeDriver與Capabilities & ChromeOptions

我在想特別在custom profile。如果你能以某種方式從ChromePortable中獲得並使用默認ChromeDriver加載它?

編輯:也許this可以幫助

1
String chromePath = "M:/my/googlechromeporatble.exe path"; 
    String chromedriverpath="M:/my/chromedriver.exe path"; 
    ChromeOptions options = new ChromeOptions(); 
    options.setBinary(chromepath); 
    System.setProperty("webdriver.chrome.driver",chromedriverpath);    
    driver = new ChromeDriver(options); 

這將調用便攜式鉻,而比本地安裝。 首先設置谷歌瀏覽器便攜路徑,然後調用chromeriver.exe