HtmlUnit can't get the js / ajax added of IFRAME

匿名 (未验证) 提交于 2019-12-03 08:50:26

问题:

I've just started learning htmlunit by gargoylesoftware and I have a problem. There is an iframe on a page, which appears after a button click. When i try to get this iframe by name I get a ElementNotFoundException. Also I tried page.getFrames() and it returns frames, but there is no frame that i'm looking for or it is blank. So It looks like js/ajax didn't update it. I work on jcpenny(dot)com and problem appears when I try to "checkout" from "My Bag" page Here is my WebClient settings

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()); 

回答1:

This may be late answer, but it will be useful for others in the future.

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

hope this will help to identify iframes.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!