How to launch Chrome browser from java

Is there any clever way to launch the Chrome browser from a java class? I am asking because I would like to be running an application that requires the Chrome browser on a computer with Internet Explorer as the default browser and java 1.4.2 installed.

thank

+3


source to share


2 answers


You can do 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();
}

      



If you know where Chrome is installed.

+6


source


You can try Selenium Here :

import org.openqa.selenium.chrome.ChromeDriver;
public class App
{
    public static void main(String[] args) throws Throwable
    {
        ChromeDriver driver = new ChromeDriver();

        System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");

        // And now use this to visit Google
        driver.get("http://www.google.com");
}

      

}



Add Maven Dependency:

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.42.2</version>
    </dependency>

      

+1


source







All Articles