admin管理员组文章数量:1332353
I am using htmlunit to automatically go through a website. Here is the problem:
I want to click on an anchor in order to display a new page of a given table.
Here is the anchor:
<a href="javascript:__doPostBack('GridView1','Page$7')">7</a>
Here is my code:
final HtmlAnchor a = page2.getAnchorByText("7");
HtmlPage page3 = a.click();
System.out.println(page2.getWebResponse().getContentAsString())
System.out.println(page3.getWebResponse().getContentAsString());
I do not have any error message. When I pare my print out, they are identical, and yet they shouldn't be, as I just clicked on an anchor. First print out should display a certain page of the table, a the second print out another one.
The stackoverflow post struggling to click on link within htmlunit renders a very similar problem, however his solution (setting the browser version to the webclient) does not appear to work in my case.
I am using htmlunit to automatically go through a website. Here is the problem:
I want to click on an anchor in order to display a new page of a given table.
Here is the anchor:
<a href="javascript:__doPostBack('GridView1','Page$7')">7</a>
Here is my code:
final HtmlAnchor a = page2.getAnchorByText("7");
HtmlPage page3 = a.click();
System.out.println(page2.getWebResponse().getContentAsString())
System.out.println(page3.getWebResponse().getContentAsString());
I do not have any error message. When I pare my print out, they are identical, and yet they shouldn't be, as I just clicked on an anchor. First print out should display a certain page of the table, a the second print out another one.
The stackoverflow post struggling to click on link within htmlunit renders a very similar problem, however his solution (setting the browser version to the webclient) does not appear to work in my case.
Share Improve this question edited May 23, 2017 at 11:47 CommunityBot 11 silver badge asked Sep 1, 2012 at 9:22 user1190900user1190900 851 silver badge6 bronze badges2 Answers
Reset to default 6Maybe you need to wait for the javascript to excute and load first. I suggest to use the following mand:
webClient.waitForBackgroundJavaScript(1000);
or even:
JavaScriptJobManager manager = page.getEnclosingWindow().getJobManager();
while (manager.getJobCount() > 0) {
Thread.sleep(100);
}
and yet another option:
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setAjaxController(new AjaxController(){
@Override
public boolean processSynchron(HtmlPage page, WebRequest request, boolean async)
{
return true;
}
});
final HtmlAnchor a = page2.getAnchorByText("7"); HtmlPage page3 = a.click();
// add this client.waitForBackgroundJavaScriptStartingBefore(10000); here client.waitForBackgroundJavaScriptStartingBefore(10000);
System.out.println(page2.getWebResponse().getContentAsString()) System.out.println(page3.getWebResponse().getContentAsString());
本文标签: javaClicking on javascript anchor with htmlunit does not seem to workStack Overflow
版权声明:本文标题:java - Clicking on javascript anchor with htmlunit does not seem to work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742321577a2452895.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论