使用HtmlUnit单击锚点时发生错误

时间:2012-09-28 12:52:52

标签: htmlunit

使用HtmlUnit我可以为网页获取此Image元素

 <pre> <a onclick="return OnSubmitValidateSignUp();return ValidEmail();" id="lnkSave"    tabindex="10" class="create" href="javascript:__doPostBack('lnkSave','')"></a> </pre>

使用

     <i> HtmlAnchor button = (HtmlAnchor) currentPage.getByXPath("//* [@id=\"lnkSave\"]").get(0);     
System.out.println(" anchor "+ button.getId());</i>

但是当我发现button.click();后发生错误。

Sep 28, 2012 6:39:59 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Exception in thread "JS executor for com.gargoylesoftware.htmlunit.WebClient@f27a6e" java.lang.OutOfMemoryError: Java heap space
at java.util.Hashtable.put(Hashtable.java:458)
    at java.util.Properties.load0(Properties.java:392)
    at java.util.Properties.load(Properties.java:341)
    at java.util.PropertyResourceBundle.<init>(PropertyResourceBundle.java:130)
    at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2610)
    at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1436)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1400)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1354)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1354)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是一个javascript问题。看来你有一些javascript附加到按钮的OnClick事件。首先尝试禁用JS,如果可能的话。第二次尝试看看这个答案:HtmlUnit is throwing Out Of Memory and maybe leaking memory,它可能会有帮助。