Search code examples
htmlunit

unable to setup HTMLUNIT in eclipse


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"


Solution

  • 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