java - HTMLUnit Many Error in Basic Example -


i'm trying basic example working using htmlunit.

i trying code search drill on homedepot website:

try (final webclient webclient = new webclient(browserversion.chrome)) {            // first page         final htmlpage page1 = webclient.getpage("http://www.homedepot.ca");          // form dealing , within form,          // find submit button , field want change.         final htmlform form = page1.getformbyname("search_terms_form");          final htmlsubmitinput button = form.getinputbyvalue("go");         final htmltextinput textfield = form.getinputbyname("q");          // change value of text field         textfield.setvalueattribute("drill");          // submit form clicking button          button.click();             system.out.println(page1.gettitletext());     } 

judging error messages, appears code button , textfield incorrect. i've tried variations of getting name, id, , value not having luck. suggestions?

any comments/feedback appreciated!

edit: here's error code. when comment out button , textfield initializations, error goes away.

exception in thread "main" com.gargoylesoftware.htmlunit.elementnotfoundexception: elementname=[input] attributename=[value] attributevalue=[go] @ com.gargoylesoftware.htmlunit.html.htmlform.getinputbyvalue(htmlform.java:795) @ hdsearch.main(hdsearch.java:30) 

ed hinted reason. if still need help, can use below button given class name:

try (final webclient webclient = new webclient(browserversion.chrome)) {     // first page     final htmlpage page1 = webclient.getpage("http://www.homedepot.ca");      // form dealing , within form,      // find submit button , field want change.     final htmlform form = page1.getformbyname("search_terms_form");      final htmlelement button = form.getfirstbyxpath("//button[@class='search-button']");     final htmltextinput textfield = form.getinputbyname("q");      // change value of text field     textfield.setvalueattribute("drill");      // submit form clicking button      button.click();     system.out.println(page1.gettitletext()); } 

}


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -