Eclipse 为什么HtmlButton object.click()在HtmlUnit中不起作用?
我从一个html+javascipt页面获得了htmlbutton,但我的代码不起作用(Eclipse中的JUnit+HtmlUnit) 代码是:Eclipse 为什么HtmlButton object.click()在HtmlUnit中不起作用?,eclipse,junit4,htmlunit,Eclipse,Junit4,Htmlunit,我从一个html+javascipt页面获得了htmlbutton,但我的代码不起作用(Eclipse中的JUnit+HtmlUnit) 代码是: final HtmlPage page = (HtmlPage)webClient.getPage(url); final HtmlForm form = page.getFormByName("registrationForm"); final HtmlButton button=(HtmlButton)page.getElementById("s
final HtmlPage page = (HtmlPage)webClient.getPage(url);
final HtmlForm form = page.getFormByName("registrationForm");
final HtmlButton button=(HtmlButton)page.getElementById("submit1");
final HtmlTextInput phone = form.getInputByName("phoneno");
phone.setValueAttribute("1234567890");
// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click(); //this doesn't work
final String pageAsXml = page2.asText();
System.out.println(pageAsXml);
行注释“这不起作用”有一些问题。没有错误,但它不起作用。
webclient构造函数有什么问题吗?是否需要将浏览器版本指定为参数?这在eclipse中有效吗
final HtmlPage page = (HtmlPage)webClient.getPage(url);
final HtmlForm form = page.getFormByName("registrationForm");
final HtmlButton button=(HtmlButton)form.getElementById("submit1");
//instead of page try using the form
final HtmlTextInput phone = form.getInputByName("phoneno");
phone.setValueAttribute("1234567890");
// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click(); //this doesn't work
final String pageAsXml = page2.asText();
System.out.println(pageAsXml);
//Let me know if it works.