I,m使用HtmlUnit版本2.43。 当我单击按钮时,将调用函数javascript。该函数创建一个链接(新URL),该新页面需要Cookie(JSESSIONID),执行后,结果将显示在标签DIV中。 但是我尝试了所有事情,但无法做到这一点。 请有人帮我!
代码: WebClient客户端=新的WebClient(BrowserVersion.CHROME); WebClientOptions options = client.getOptions();
CookieManager cookieManager = client.getCookieManager();
cookieManager.setCookiesEnabled(true);
client.setCookieManager(cookieManager);
client.getOptions().setJavaScriptEnabled(true);
client.setAjaxController(new NicelyResynchronizingAjaxController());
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
client.getOptions().setCssEnabled(false);
HtmlTextInput inputCaptcha = paginaAfterConsultaIdentificadorCaptcha.querySelector("input[name='questionCL']");
inputCaptcha.setValueAttribute("gr5w4");
HtmlPage paginaInfLote = ((HtmlButtonInput) paginaAfterConsultaIdentificadorCaptcha.getElementById("botao_continuar")).click();
client.setJavaScriptTimeout(10000);
System.out.println(paginaInfLote.asXml());
<!-- I tried set to new cookie: -->
Iterator<Cookie> index = cookies4.iterator();
while (index.hasNext()) {
vSessionId = index.next().toString();
System.out.println(index.next());
break;
}
String vValueCookie = vSessionId.substring(11, vSessionId.indexOf(";"));
Date dt = new Date();
Calendar c = Calendar.getInstance();
c.setTime(dt);
c.add(Calendar.DATE, 1);
dt = c.getTime();
Cookie cookie = new Cookie("www.licitacoes-e.com.br", "JSESSIONID", vValueCookie, "/", dt, false);
cookieManager.addCookie(cookie);
client.setCookieManager(cookieManager);
<!-- Fim set cookie -->