2016-05-18 263 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

相关问题