Unable to open Google Chrome Portable with Selenium

你。 提交于 2019-12-08 08:52:28

问题


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\\GoogleChrom‌​ePortable.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!