我从一个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("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);这行评论"this‘t work“有一些problem.there is no error,但它不工作。webclient构造函数有什么问题吗?我们需要指定浏览器版本作为参数吗?这能在eclipse中工作吗?
发布于 2011-11-29 22:40:33
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.https://stackoverflow.com/questions/4872556
复制相似问题