我无法从页面获得javascript响应。关注我的代码... jquery不兼容?
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_52);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setTimeout(3000);
webClient.waitForBackgroundJavaScript(3000);
webClient.getOptions().setCssEnabled(true);
HtmlPage page = webClient.getPage("");
HtmlForm form = (HtmlForm) page.getElementByName("tabview-consultas-publicas:formExtratos");
HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) form.getRadioButtonsByName("tabview-consultas-publicas:formExtratos:tipoInformacao").get(0);
radioButton.setAttribute("checked","");
radioButton.setChecked(true);
HtmlButton button = form.getButtonByName("tabview-consultas-publicas:formExtratos:j_idt156");
button.click();
System.out.println(page.asText());
System.exit(0);
根据您提供的信息,很难给您一些建议。至少没有网址让我们有机会重现你的问题,你没有告诉我们任何日志输出。
所以这里有我的建议:
关于按钮点击没有;截至今天,或多或少有三种按钮
btn.click(); // wait for the async js webClient.waitForBackgroundJavaScript(20000); // get the current page from the window in case it was replaced by some js magic newPage = (HtmlPage) page.getEnclosingWindow().getTopWindow().getEnclosedPage();
希望有所帮助