I was looking for a way to control google chrome or firefox or internet explorer using java.
Say like I simply call a function passing the URL as the parameter and the page will be loaded.
I'm writing a java program that I can use to automatically save files on server so that I don't have to login to cpanel and then make it manually, I can use php to do save the file(s) but I need to test how the site design is. But as I'm开发者_StackOverflow社区 new to Java I don't have much knowledge of doing things.
Thanks, Sreejith
I doubt if there is a way to control the web browser without knowing or having its APIs. If the web browser you want to control does not provide an API for your java then it is impossible.
If you want to be able to fully control your web browser, you should try to develop plug-in using their APIs, not via JAVA.
If you just want to open a link in your default web browser, try this:
java.awt.Desktop.getDesktop().browse(java.net.URI.create("http://google.com"));
This code opens the url in your default web broswer. I used this to open lots of forum pages because it requires login session from my web browser and saves the pages all at once.
You might be better off using cPanel XML api for what you are trying.
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>
精彩评论