[Se2] [HtmlUnit] How to use WaitingRefreshHandler or ThreadedRefreshHandler?

568 views
Skip to first unread message

Felipe Knorr Kuhn

unread,
Oct 3, 2010, 7:22:52 PM10/3/10
to seleniu...@googlegroups.com, webd...@googlegroups.com
Hello all,

I'm trying to use HtmlUnitDriver to open http://www.terra.com.br and got the following exception:

Exception in thread "main" org.openqa.selenium.WebDriverException: java.lang.RuntimeException: Refresh to http://www.terra.com.br/portal/ (180s) aborted by HtmlUnit: Attempted to refresh a page using an ImmediateRefreshHandler which could have caused an OutOfMemoryError Please use WaitingRefreshHandler or ThreadedRefreshHandler instead.
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.6.4', java.version: '1.6.0_20'
Driver info: driver.version: htmlunit
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:280)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:262)
at parsers.Terra.main(Terra.java:16)
Caused by: java.lang.RuntimeException: Refresh to http://www.terra.com.br/portal/ (180s) aborted by HtmlUnit: Attempted to refresh a page using an ImmediateRefreshHandler which could have caused an OutOfMemoryError Please use WaitingRefreshHandler or ThreadedRefreshHandler instead.
at com.gargoylesoftware.htmlunit.ImmediateRefreshHandler.handleRefresh(ImmediateRefreshHandler.java:58)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeRefreshIfNeeded(HtmlPage.java:1279)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:218)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:427)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:303)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:360)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:274)
... 2 more

After Googling up a bit, I noticed this is a common HtmlUnit behavior, but I couldn't find any pointers to change the refresh handler, especially when using WebDriver.

Thanks,

FK

Simon Stewart

unread,
Oct 4, 2010, 11:50:27 AM10/4/10
to webd...@googlegroups.com, seleniu...@googlegroups.com
One way to make this change is to subclass the HtmlUnitDriver and
override the "modifyWebClient" method. The other way is to wait for
the (soon to be released) a6, which has this change already made.

Simon

> --
> You received this message because you are subscribed to the Google Groups
> "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to
> webdriver+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/webdriver?hl=en.
>

Felipe Knorr Kuhn

unread,
Oct 4, 2010, 1:02:19 PM10/4/10
to webd...@googlegroups.com, seleniu...@googlegroups.com
Thank you, Simon.

I guess I'll just wait for a6 :)

FK

DKay

unread,
Dec 1, 2013, 1:01:33 PM12/1/13
to webd...@googlegroups.com, seleniu...@googlegroups.com
I know that this is an old thread but I  want to post this as it might help others as I had the same problem.

Simon's advice worked for me. I got it to work by creating an annonymous class and overriding the modifyWebClient method.

This was my code:

HtmlUnitDriver driver = new HtmlUnitDriver() {
@Override
            protected WebClient modifyWebClient(WebClient client) { 
                client.setRefreshHandler(new ThreadedRefreshHandler());
return client; 
            } 
        }; 
Reply all
Reply to author
Forward
0 new messages