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

发布于 2024-10-15 21:39:13 字数 692 浏览 1 评论 0原文

我从一个 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);

注释“这不起作用”的行有一些问题。没有错误,但它不起作用。 webclient构造函数有问题吗?我们需要指定浏览器版本作为参数吗?这会在日食中工作吗?

i got htmlbutton from one html+javascipt page but my code does not work(JUnit+HtmlUnit in Eclipse)
The code is :

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);

the line commented "this doesn't work" has some problem.there is no error but it isn't working.
is there any problem with webclient constructor? do we need to specify browser version as argument? will this work in eclipse?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半寸时光 2024-10-22 21:39:13
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.
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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文