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 o
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>
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.