Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch chrome browser from java

Is there any smart way to launch the chrome browser from a java class? I'm asking because I would like a smart way to launch an application that required a chrome browser on a machine that has internet explorer as a default browser and java 1.4.2 installed.

thanks

like image 945
Richie Avatar asked Aug 15 '14 03:08

Richie


People also ask

How do I open Chrome in eclipse?

We can launch Chrome browser via Selenium. Java JDK, Eclipse and Selenium webdriver should be installed in the system before Chrome browser is launch. Navigate to the link: https://chromedriver.chromium.org/downloads. Select the Chrome driver link which matches with the Chrome browser in our system.

How do you invoke a browser?

Understanding the browser launching command WebDriver driver = new FirefoxDriver(); This is the java implementation of launching a browser in Selenium. Here, 'WebDriver' is an interface and we are creating a reference variable 'driver' of type WebDriver, instantiated using 'FireFoxDriver' class.

How do I open Chrome as another user using Selenium?

We can open Chrome default profile with Selenium. To get the Chrome profile path, we need to input chrome://version/ in the Chrome browser and then press enter. We need to use the ChromeOptions class to open the default Chrome profile. We need to use the add_argument method to specify the path of the Chrome profile.


1 Answers

You can execute chrome.exe like this:

try {
    Process p = Runtime.getRuntime().exec("\"/Program Files (x86)/Google/Chrome/Application/chrome.exe\"");
    p.waitFor();
    System.out.println("Google Chrome launched!");
} catch (Exception e) {
    e.printStackTrace();
}

Provided you know where Chrome is installed.

like image 152
bdunn Avatar answered Sep 24 '22 02:09

bdunn