title: got error and exceptions using HtmlUnit in Java
body: <p>I just wrote simple code in Java (using Eclipse editor with OS X, jdk1.8.0_25.jdk):</p>
  
  <pre><code>String url = "http://www.delfi.lt";
  final WebClient webClient = new WebClient(BrowserVersion.CHROME);
  final HtmlPage page = webClient.getPage(url);
  webClient.closeAllWindows();
  System.out.println("Done!");
  </code></pre>
  
  <p>and got the following error:</p>
  
  <pre><code>Exception in thread "main" ======= EXCEPTION START ========
  EcmaError: lineNumber=[1546] column=[0] lineSource=[&lt;no source&gt;] name=[TypeError] sourceName=[script in http://www.delfi.lt/ from (1545, 32) to (1548, 10)] message=[TypeError: Cannot find function getElementsByClassName in object [object HTMLDocument]. (script in http://www.delfi.lt/ from (1545, 32) to (1548, 10)#1546)]
  com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function getElementsByClassName in object [object HTMLDocument]. (script in http://www.delfi.lt/ from (1545, 32) to (1548, 10)#1546)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705)
      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:591)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:566)
      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:975)
      at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:349)
      at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:409)
      at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:274)
      at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:288)
      at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:741)
      at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
      at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:701)
      at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170)
      at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072)
      at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)
      at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330)
      at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3126)
      at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2093)
      at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
      at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
      at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)
      at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
      at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:965)
      at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:247)
      at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:193)
      at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
      at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
      at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:468)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:342)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:392)
      at ClickingDelfi.submitComment(ClickingDelfi.java:26)
      at Main.run(Main.java:28)
      at Main.main(Main.java:13)
  Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function getElementsByClassName in object [object HTMLDocument]. (script in http://www.delfi.lt/ from (1545, 32) to (1548, 10)#1546)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3629)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3613)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3634)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3650)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3714)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2233)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2215)
      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1333)
      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
      at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:582)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:690)
      ... 34 more
  Enclosed exception: 
  net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function getElementsByClassName in object [object HTMLDocument]. (script in http://www.delfi.lt/ from (1545, 32) to (1548, 10)#1546)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3629)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3613)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3634)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3650)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3714)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2233)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2215)
      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1333)
      at script(script in http://www.delfi.lt/ from (1545, 32) to (1548, 10):1546)
      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
      at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:582)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:690)
      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:591)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:566)
      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:975)
      at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:349)
      at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:409)
      at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:274)
      at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:288)
      at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:741)
      at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
      at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:701)
      at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170)
      at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072)
      at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)
      at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330)
      at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3126)
      at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2093)
      at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
      at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
      at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)
      at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
      at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:965)
      at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:247)
      at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:193)
      at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
      at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
      at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:468)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:342)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:392)
      at ClickingDelfi.submitComment(ClickingDelfi.java:26)
      at Main.run(Main.java:28)
      at Main.main(Main.java:13)
  ======= EXCEPTION END ========
  </code></pre>
  
  <p>Using url as <a href="https://www.google.lt" rel="nofollow">https://www.google.lt</a> it worked. Is it only working with certain pages? Is there any alternatives that can be used with the url I use?</p>