我刚刚开始通过 gargoylesoftware 学习htmlunit,但遇到了问题。页面上有一个 iframe,在单击按钮后出现。当我尝试按名称获取此 iframe 时,我得到一个ElementNotFoundException
. 我也尝试过page.getFrames()
,它返回帧,但没有我正在寻找的帧或者它是空白的。所以看起来 js/ajax 没有更新它。我在 jcpenny(dot)com 上工作,当我尝试从“我的包”页面“结帐”时出现问题 这是我的 WebClient 设置
BrowserVersion bv = BrowserVersion.CHROME_16;
bv.setUserAgent("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
CookieManager cm = new CookieManager();
cm.clearCookies();
cm.setCookiesEnabled(true);
WebClient webClient = new WebClient(bv);
webClient.setCookieManager(cm);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setJavaScriptTimeout(15000);
webClient.setCssErrorHandler(new SilentCssErrorHandler());
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.waitForBackgroundJavaScript(15000);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setUseInsecureSSL(true);
webClient.setRefreshHandler(new ThreadedRefreshHandler());