How to start chrome using Java?
For Windows the code is just as simple as below.
Runtime.getRuntime().exec(new String[]{"cmd", "/c", "start chrome http://localhost:8080"});
Is there something like above?
How to start chrome using Java?
For Windows the code is just as simple as below.
Runtime.getRuntime().exec(new String[]{"cmd", "/c", "start chrome http://localhost:8080"});
Is there something like above?
In Linux you can use like this:
Runtime.getRuntime().exec(new String[]{"bash", "-c", "/path/to/chrome http://yourwebsite.com"});
Replace the /path/to/chrome with the path in your system. Generally Google Chrome is installed at /opt/google/chrome/chrome
Or you can use google-chrome like this:
Runtime.getRuntime().exec(new String[]{"bash", "-c", "google-chrome http://yourwebsite.com"});
If you want to open up in chromium browser in Linux use it like this:
Runtime.getRuntime().exec(new String[]{"bash", "-c", "chromium-browser http://yourwebsite.com"});
For MAC OS try like this:
Runtime.getRuntime().exec(new String[]{"/usr/bin/open", "-a", "/Applications/Google Chrome.app", "http://yourwebsite.com/"});
You can use Selenium.
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");
}
>>> Check here (Note: Java File is Compiled and run by commands on Terminal)
File name: Test.java
public class Test {
public static void main(String[] args) {
try {
System.out.println("Executing command to open a chrome tab with terminal command!");
Runtime.getRuntime().exec(new String[]{"bash", "-c", "google-chrome https://stackoverflow.com/"});
System.out.println("A New tab or window should get opened in your Chrome Browser with Stack Overflow website!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
/**here
google-chrome https://stackoverflow.com/ -> terminal command to open a new chrome tab or window with the stack-overflow website.
**/