0

Please assist me in setting up htmlunit with eclipse. I am tryning to fill a form and submit it through the code

Here is my code

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

public class Ullas {


        public static void main(String[] args) {

            WebClient client = new WebClient();
            try
            {
                HtmlPage currentPage = (HtmlPage)client.getPage("http://xx.com");
                HtmlForm form = (HtmlForm) CurrentPage.getElementById("login_form");
                final HtmlTextInput textField = form.getInputByName("nm");
                textField.setValueAttribute("mak");
                final HtmlSubmitInput button = form.getInputByName("submitbutton");

                //currentPage = form.getAcceptAttribute();

                 button.click();
            }
            catch(Exception ex)
            {
                System.out.println("Some form of error happened !");
            }


        }

}

I did included all the libraries but when I run the application it keeps on saying "the user operation is waiting for'building workspace' too complete"

Mayank Vaid
  • 330
  • 1
  • 7
  • 18
  • Eclipse can have a tendency to hang sometimes for no apparent reason (usually because of memory). Try restarting the application, if you already did it; does the problem persist? – PseudoAj May 15 '16 at 08:30
  • Problem resolved but could you explain me how the above code should work means should it pop up the page that comes after the form is submited or what because when i am executing my code. It is doing nothing – Mayank Vaid May 15 '16 at 08:50
  • The above code opens a webpage, inputs text and hits submit button. I assume you have directed it to right domain, then it should display the result. – PseudoAj May 15 '16 at 08:54
  • Yes I have directed it to the correct domain but It doesn't display any result – Mayank Vaid May 15 '16 at 09:05
  • It doesn't throw any error? – PseudoAj May 15 '16 at 09:10
  • no it doesn't throw any error neither it shows any web page – Mayank Vaid May 15 '16 at 09:18
  • Also, I am assuming you did write some tests? Here is the link for some sample tests: http://www.aviyehuda.com/blog/2011/05/16/htmlunit-a-quick-introduction/ http://www.programcreek.com/java-api-examples/index.php?api=com.gargoylesoftware.htmlunit.WebClient – PseudoAj May 15 '16 at 09:34

1 Answers1

0

Eclipse has this weird tendency to hang (frequently due to memory). Most of the times restarting your instance can fix the issue. Alternately, running eclipse.exe -clean should also fix the problem as eclipse cleans all the cache data while starting. The problem has been reported by several users, I attaching links for your reference:

https://www.genuitec.com/forums/topic/myeclipse-hangs-on-building-workspace-0/

User Operation is waiting for "Building Workspace"

https://www.eclipse.org/forums/index.php/t/512454/

https://bugs.eclipse.org/bugs/show_bug.cgi?id=77946

Community
  • 1
  • 1
PseudoAj
  • 5,234
  • 2
  • 17
  • 37