How can I open IE from java and perform operations like click () etc. Through java?

I will not be entering the site via Java and performing operations like clicking, adding text to a text box, etc. via Java.

+2


source to share


6 answers


I suggest using a testing framework like HtmlUnit . Even with this for testing purposes, it's a great software "navigator" of remote websites.

Here's a sample code from the site showing how to navigate to a page and fill out a form:



public void submittingForm() throws Exception {
   WebClient webClient = new WebClient();
   HtmlPage page1 = webClient.getPage("http://some_url");
   HtmlForm form = page1.getFormByName("myform");
   HtmlSubmitInput button = form.getInputByName("submitbutton");
   HtmlTextInput textField = form.getInputByName("userid");
   textField.setValueAttribute("root");
   HtmlPage page2 = button.click();
}

      

+6


source


You can start it with

Runtime.getRuntime().exec("command-line command to launch IE");

      



then use Java Robot class to send mouse clicks and fill text. This seems rather crude, however, and you can probably do better by contacting the web server directly (bypassing the browser entirely).

+4


source


The answer to this question might be helpful.

But you should consider direct HTTP as the best way to interact with websites.

+1


source


If you really want "real" IE you can try Watij , if you only want browser features in java I recommend HttpClient

Update: Since the OP shown using a real browser is unnecessary / unnecessary. An example of form login using HttpClient can be found here: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientFormLogin.java

0


source


You can also use Canoo's WebTest, which actually uses HTMLUnit, but with an extra layer on top of it. It should be easier to get started with the script, and it contains additional abstractions for sending emails, checking output, etc.

http://webtest.canoo.com/webtest/manual/WebTestHome.html

0


source


You can also try Selenium. It's free and has a pretty nice skin for IE.

0


source







All Articles