Reputation: 4540
I am in the process of creating a Java program that goes on the internet, signs in to website accounts and posts stuff. E.g. Run Program - > Tumblr - > Post "Helow World" -> Log Out of Tumblr.
I am currently using the Robot class to do this... http://download.oracle.com/javase/6/docs/api/java/awt/Robot.html
But looking ahead, I see a daunting future (web page updates will crash the program because it is based on coordinates, mouse clicks and keyboard.)
Is there someway I can do web browser automation? (e.g. surfing to websites, filling out forms etc.) (preferably in Java, python, C++ or php)
Upvotes: 5
Views: 21786
Reputation: 41
hy i wanted to have a same program as you which is surfing on the internet.
i used selenium in chrome. If you want to use selenium you have to download from http://www.seleniumhq.org/download/ --- the latest version and implement in neatbeans or eclipse the jar files. (Selenium Client & WebDriver Language Bindings, Selenium Standalone Server) After this you have to download from google https://sites.google.com/a/chromium.org/chromedriver/ -- chrome driver also the latest version extract the file and save on your pc. Here is the code what i used:
package teszt;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Teszt {
public static void main(String[] args) {
String exePath = "C:\\Users\\Magor\\Downloads\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
}}
Upvotes: 0
Reputation: 2857
You can use HTMLUnit to program java code to simulate browser usage.
download jar file at : http://www.java2s.com/Code/Jar/h/Downloadhtmlunit211jar.htm
Get Started at : http://htmlunit.sourceforge.net/gettingStarted.html
Upvotes: 1
Reputation: 21
You can also try JExplorer Teamdev: Jexplorer. But it's not for free unless you are a student or working in an Open Source community. This tool uses swings to simulate the Internet Explorer. Watij is based on JExplorer
Upvotes: 2
Reputation: 3426
Selenium is a great option for exactly what you need. Not only can you write scripts for it in java (as well as many other languages) but you can install the browser plugin and have it record your actions to quickly learn it's syntax.
Upvotes: 9
Reputation: 272217
Watij is a Java-based web testing framework that will drive a web browser. Although it's nominally for testing, it can do what you want. You can intelligently search for button/controls to drive, and because it's controlling the browser, all the client side functionality (scripts etc.) will be triggered correctly.
Upvotes: 2