【问题标题】:HtmlUnit can't get the js / ajax added of IFRAMEHtmlUnit 无法获取 IFRAME 添加的 js/ajax
【发布时间】:2012-10-03 17:15:47
【问题描述】:

我刚开始通过 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());

【问题讨论】:

    标签: java javascript ajax iframe htmlunit


    【解决方案1】:

    这可能是迟到的答案,但将来对其他人有用。

    HtmlPage currentPage = (HtmlPage)webClient.getWebWindowByName("Frame Name").getEnclosedPage();
    

    希望这将有助于识别 iframe。

    【讨论】:

    • 如果 iframe 没有名称怎么办?我试图访问的 iframe 没有名称。
    猜你喜欢
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 2021-01-08
    • 2016-04-20
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多