[Webtest] "Cannot call method "submit" of undefined" Error when test a login page

Marc Guillemot Marc Guillemot <mguillemot@yahoo.fr>
Tue, 02 Sep 2008 14:03:30 +0200


if your page really doesn't have any JS error then it means that your JS
code is not supported by HtmlUnit, or more exactly by the HtmlUnit
version you're using. If you use a recent build of WebTest, you will
have HtmlUnit-2.2 shipped with it and if the error still exist, you can
probably try to replace the HtmlUnit-2.2.jar by a snapshot of
HtmlUnit-2.3. If the problem persists, then I'm interested if you could
provide a minimal testcase allowing to reproduce the problem and report
it to the HtmlUnit project.

As workaround, you can configure your webtest to ignore JS errors (but
then you won't detect JS errors, even "real" ones):
  <option name="ThrowExceptionOnScriptError" value="false"/>

Blog: http://mguillem.wordpress.com

lostinheaven.lee@gmail.com wrote:
> Hi, Everyone
> I wrote an easy testcase for a login page. Just invoke the url ,then
> find the button by xpath and click it.The form will submint login datas
> and goto another page.
> the ID and pass word is write in the html, so no need to set input.
> I'm srue the xpath is right , it gets wrong at the last step.I don't
> know is it Script problem or the JS in the page have any bug. and  I
> don't think it's the method "submit" is the real point.
> It will be greatly appreciate if anyone could tell me the reason or your
> opinion.
> Please DO reply me if you had met the same problem.
> thanks
> * The error message:*
> JavaScript error loading page http://192.xxx.xx.xx:8080/Ash/: TypeError:
> Cannot call method "submit" of undefined (script in
> http://192.xxxxx.xx:8080/Ash/ from (16, 31) to (0, 0)#37)
> *My Script:*
> <?xml version="1.0"?>
> <!DOCTYPE project SYSTEM "../dtd/Project.dtd">
> <project default="ifdmsLogintest">
>     <target name="ifdmsLogintest">
>         <webtest name="check the login founction">
>             <invoke url="http://192.xxx.xx.xx:8080/Ash/" description="Go
> to asahi login"/>
>             <clickButton xpath="//input[@type = 'button']"
> description="login" />
>         </webtest>
>     </target>
> </project>