当前位置: 动力学知识库 > 问答 > 编程问答 >

Page does not change after I set an option button with HtmlUnit

问题描述:

I am using HtmlUnit to navigate through the Web of knowledge web page. I am using the code below to set an option button so that results on the page would be sorted appropriately. Unfortunately, nothing happens when I execute the code. Results on the page remains sorted in the same way as they ware before.

HtmlSelect ssort = (HtmlSelect) pageX.getFirstByXPath("//*[@id=\'topNavBar\']/tbody/tr/td[3]/form/select");

HtmlOption optionA = ssort.getOptionByValue("LC.D;PY.D;AU.A;SO.A;VL.D;PG.A");

ssort.setSelectedAttribute(optionA, true);

ssort.click();

I debuged the code and there is no errors. Do you have any idea what am I doing wrong?

网友答案:

As a general rule, functions like the .click() and .setSelectedAttribute(HTMLOption, boolean)(See JavaDoc) will return a HTMLPage that in most cases is the same as the current one, however in your case it will return a different HTMLPage. So to capture the new page you just need to assign the return value to a HTMLPage.

N.B: You could also use getCurrentWindow() on the WebClient instance.

分享给朋友:
您可能感兴趣的文章:
随机阅读: