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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With