HtmlUnit cannot get js / ajax added by IFRAME

I just started learning htmlunit with gargoylesoftware and I have a problem. There is an iframe on the page that appears after clicking the button. When I try to get this iframe by name, I get an ElementNotFoundException . I also tried page.getFrames() and it returns frames, but there is no frame I'm looking for, or it is empty. So it looks like js / ajax has not updated it. I am working on jcpenny (dot) com and the problem occurs when I try to β€œcheck” on the β€œMy bag” page. Here are the settings of my 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()); 
+4
source share
1 answer

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

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

hope this helps determine iframes.

+3
source

Source: https://habr.com/ru/post/1439473/


All Articles