2015-09-28 39 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