HTMLUNIT锚点请点击

时间:2018-07-27 02:31:59

标签: anchor htmlunit

我的锚点:

<div class="button-cont main">

          <input type="hidden" name="ak.ok" value="" />
          <input type="hidden" name="ak.cancel" value="" />

      <a id="log-in" onclick="postOk();" class="log-button normal allow" title="LOG IN">
     LOG IN

          </a> 

        </div>

我的代码如下:

 HtmlAnchor link = null;
        List<HtmlAnchor> anchors = page.getAnchors();
        for (HtmlAnchor anchor : anchors) {
            String str = anchor.asText();

            if (anchor.asText().startsWith("LOG IN"))
               link = anchor;
        }


        HtmlPage newPage = link.click();

我面临的问题是“ newPage”仍然保留在旧页面上,而应该将我带到另一个页面上。

我的Webclient设置和选项是:

    webClient.getOptions().setRedirectEnabled(true);
    webClient.getOptions().setUseInsecureSSL(true);
    webClient.getOptions().setJavaScriptEnabled(false);                                                         
    webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
    webClient.getOptions().setCssEnabled(false);
    webClient.getOptions().setAppletEnabled(false);
    webClient.waitForBackgroundJavaScript(1000);
    webClient.getOptions().setThrowExceptionOnScriptError(false);

1 个答案:

答案 0 :(得分:0)

解决了该问题,以下内容奏效了。

    webClient.getOptions().setJavaScriptEnabled(true); 
    webClient.waitForBackgroundJavaScript(1000);