问题
Using below code trying to access google chrome portable browser.
System.setProperty("webdriver.chrome.driver","C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChromePortable.exe");
driver=new ChromeDriver();
Browser opened but immediately closing with the below exception
Exception:
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.
Can anyone help me how to access Google chrome portable browser with Selenium Webdriver.
回答1:
Below code successfully invoked Google chrome portable browser.
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);
回答2:
Use Chromedriver.exe fro running your test cases on Chrome Browser.
String ChromeDriverPath= "path\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", ChromeDriverPath);
WebDriver driver=new ChromeDriver();
Chromedriver exe is available at
http://www.seleniumhq.org/download/
Just Extract it and give the path of Chromedriver.exe
Do one thing :
Public class processclass{
Process getBrowserProcess() {
Process p = null;
try {
p = Runtime.getRuntime()
.exec("C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChromePortable.exe");
} catch (IOException e) {
e.printStackTrace();
}
return p;
}
}
And another class will be containing your test case. So create a object of the above class let's say :
processclass Object = new processclass();
Object.getBrowserProcess();
And then run your driver command.
Hope this help you..
来源:https://stackoverflow.com/questions/37295381/unable-to-open-google-chrome-portable-with-selenium