首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么HtmlButton object.click()在HtmlUnit中不起作用?

为什么HtmlButton object.click()在HtmlUnit中不起作用?
EN

Stack Overflow用户
提问于 2011-02-02 17:14:57
回答 1查看 729关注 0票数 0

我从一个html+javascipt页面获得了htmlbutton,但是我的代码不能工作(Eclipse中的JUnit+HtmlUnit),代码是:

代码语言:javascript
复制
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中工作吗?

EN

回答 1

Stack Overflow用户

发布于 2011-11-29 22:40:33

代码语言:javascript
复制
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.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4872556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档