"Form" is not a constructor

View: New views
16 Messages — Rating Filter:   Alert me  

"Form" is not a constructor

by Thomas Robbs :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I’ve recently come across a problem when the JavaScriptEngine.execute(…) method executes the following line of JavaScript:

 

currentForm = document.getElementById("formName");

 

… where “formName” is the id of a form on the page.

 

The exception that is thrown is:

 

org.mozilla.javascript.WrappedException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: "Form" is not a constructor. (javascript file name#105) (javascript file name #105)

 

I’m using the following BrowserVersion:

 

    public static final BrowserVersion IE_6_0_SP2_on_WINXP_SP2 = new BrowserVersion(

        BrowserVersion.INTERNET_EXPLORER, "4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",

        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)", "1.2", 6 );

 

I’ve walked through the functionality using the real browser that the above BrowserVersion represents as well as FireFox 1.0.7 and I’m not seeing any JavaScript errors on the page when it loads.

 

I’m also using a build of HtmlUnit 1.7 from 2005-12-05.

 

Any ideas as to what would cause this Exception?

 

Thanks in advance,

 

Tom

 

 


Re: "Form" is not a constructor

by Marc Guillemot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Thomas,

is

currentForm = document.getElementById("formName");

really the code at line 105 in your js file?

Can you try to produce a minimal html/js reproducing the problem?

Marc.

Thomas Robbs wrote:

> I’ve recently come across a problem when the JavaScriptEngine.execute(…)
> method executes the following line of JavaScript:
>
>  
>
> currentForm = document.getElementById("formName");
>
>  
>
> … where “formName” is the id of a form on the page.
>
>  
>
> The exception that is thrown is:
>
>  
>
> org.mozilla.javascript.WrappedException: Wrapped
> com.gargoylesoftware.htmlunit.ScriptException: "Form" is not a
> constructor. (/javascript file name/#105) (/javascript file name/ #105)
>
>  
>
> I’m using the following BrowserVersion:
>
>  
>
>     public static final BrowserVersion IE_6_0_SP2_on_WINXP_SP2 = new
> BrowserVersion(
>
>         BrowserVersion.INTERNET_EXPLORER, "4.0 (compatible; MSIE 6.0;
> Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
>
>         "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
> CLR 1.1.4322)", "1.2", 6 );
>
>  
>
> I’ve walked through the functionality using the real browser that the
> above BrowserVersion represents as well as FireFox 1.0.7 and I’m not
> seeing any JavaScript errors on the page when it loads.
>
>  
>
> I’m also using a build of HtmlUnit 1.7 from 2005-12-05.
>
>  
>
> Any ideas as to what would cause this Exception?
>
>  
>
> Thanks in advance,
>
>  
>
> Tom
>
>  
>
>  
>



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Parent Message unknown RE: Re: "Form" is not a constructor

by Ben Kyrlach :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've also experienced this problem before. Unfortunantly, I was unable to isolate the problematic code from the application under test. If you're using "prototype.js" (a standard javascript library it seems) I've found that a simple modification to that JS file solved my problem.

I havn't been able to fully investigate the problem, but it does seem to have something to do with class prototyping in JavaScript confusing HTMLUnit. Unfortunantly, I think Marc was having a bad day that day, and I didn't get much help here. If you want to see where exactly I modified the file, I'll be happy to show you.

Thanks,

Ben Kyrlach -- Operations Intern.

-----Original Message-----
From: htmlunit-user-admin@...
[mailto:htmlunit-user-admin@...]On Behalf Of Marc
Guillemot
Sent: Monday, December 12, 2005 5:10 AM
To: htmlunit-user@...
Subject: [Htmlunit-user] Re: "Form" is not a constructor


Hi Thomas,

is

currentForm = document.getElementById("formName");

really the code at line 105 in your js file?

Can you try to produce a minimal html/js reproducing the problem?

Marc.

Thomas Robbs wrote:

> I’ve recently come across a problem when the JavaScriptEngine.execute(…)
> method executes the following line of JavaScript:
>
>  
>
> currentForm = document.getElementById("formName");
>
>  
>
> … where “formName” is the id of a form on the page.
>
>  
>
> The exception that is thrown is:
>
>  
>
> org.mozilla.javascript.WrappedException: Wrapped
> com.gargoylesoftware.htmlunit.ScriptException: "Form" is not a
> constructor. (/javascript file name/#105) (/javascript file name/ #105)
>
>  
>
> I’m using the following BrowserVersion:
>
>  
>
>     public static final BrowserVersion IE_6_0_SP2_on_WINXP_SP2 = new
> BrowserVersion(
>
>         BrowserVersion.INTERNET_EXPLORER, "4.0 (compatible; MSIE 6.0;
> Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
>
>         "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
> CLR 1.1.4322)", "1.2", 6 );
>
>  
>
> I’ve walked through the functionality using the real browser that the
> above BrowserVersion represents as well as FireFox 1.0.7 and I’m not
> seeing any JavaScript errors on the page when it loads.
>
>  
>
> I’m also using a build of HtmlUnit 1.7 from 2005-12-05.
>
>  
>
> Any ideas as to what would cause this Exception?
>
>  
>
> Thanks in advance,
>
>  
>
> Tom
>
>  
>
>  
>



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

RE: Re: "Form" is not a constructor

by mraible :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ben Kyrlach wrote:
I've also experienced this problem before. Unfortunantly, I was unable to isolate the problematic code from the application under test. If you're using "prototype.js" (a standard javascript library it seems) I've found that a simple modification to that JS file solved my problem.
Please provide the patch for prototype.js as I'm having the same issue on my project.

Thanks,

Matt

Re: RE: Re: "Form" is not a constructor

by Marc Guillemot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Matt,
when you (or someone else) is able to provide an example of the failing
code, perhaps could we fix it in htmlunit itself...

Marc.

mraible (sent by Nabble.com) wrote:

>     Ben Kyrlach wrote:
>     I've also experienced this problem before. Unfortunantly, I was
>     unable to isolate the problematic code from the application under
>     test. If you're using "prototype.js" (a standard javascript library
>     it seems) I've found that a simple modification to that JS file
>     solved my problem.
>
> Please provide the patch for prototype.js as I'm having the same issue
> on my project.
>
> Thanks,
>
> Matt
> ------------------------------------------------------------------------
> View this message in context: RE: Re: "Form" is not a constructor
> <http://www.nabble.com/%22Form%22-is-not-a-constructor-t716240.html#a2212276>
> Sent from the HtmlUnit - General
> <http://www.nabble.com/HtmlUnit---General-f2599.html> forum at Nabble.com.



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Parent Message unknown RE: RE: Re: "Form" is not a constructor

by Ben Kyrlach :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Matt...
 
Here's a "patch" of sorts. A couple of notes.
 
1) This patch may break some functionality in "prototype.js". My particular project only needed to use it minimally, and the part I modified didn't affect what I was working on. Since I needed html unit, I made the change to prototype.js without considering any ramifications on other functionality.
 
2) Having little experience with patches, I'm not sure if you'll need to change the repository name (at the top of the patch file) to make it work with your set up. I hope you don't have any problems with it however.
 
That said, hope it helps.
 
Thanks,
 
Ben Kyrlach -- Operations Intern.
 
 
-----Original Message-----
From: htmlunit-user-admin@... [mailto:htmlunit-user-admin@...]On Behalf Of mraible (sent by Nabble.com)
Sent: Wednesday, January 04, 2006 6:09 PM
To: htmlunit-user@...
Subject: [Htmlunit-user] RE: Re: "Form" is not a constructor

Ben Kyrlach wrote:
I've also experienced this problem before. Unfortunantly, I was unable to isolate the problematic code from the application under test. If you're using "prototype.js" (a standard javascript library it seems) I've found that a simple modification to that JS file solved my problem.
Please provide the patch for prototype.js as I'm having the same issue on my project.

Thanks,

Matt

View this message in context: RE: Re: "Form" is not a constructor
Sent from the HtmlUnit - General forum at Nabble.com.

Index: prototype.js
===================================================================
RCS file: /usr/local/cvsroot/hobsons2.0/tim/TIMConfig/prototype.js,v
retrieving revision 1.1
diff -u -r1.1 prototype.js
--- prototype.js 5 Jan 2006 19:19:30 -0000 1.1
+++ prototype.js 5 Jan 2006 19:22:12 -0000
@@ -581,13 +581,13 @@
 
 /*--------------------------------------------------------------------------*/
 
-var Form = {
+var Form1 = {
   serialize: function(form) {
-    var elements = Form.getElements($(form));
+    var elements = Form1.getElements($(form));
     var queryComponents = new Array();
     
     for (var i = 0; i < elements.length; i++) {
-      var queryComponent = Form.Element.serialize(elements[i]);
+      var queryComponent = Form1.Element.serialize(elements[i]);
       if (queryComponent)
         queryComponents.push(queryComponent);
     }
@@ -599,7 +599,7 @@
     var form = $(form);
     var elements = new Array();
 
-    for (tagName in Form.Element.Serializers) {
+    for (tagName in Form1.Element.Serializers) {
       var tagElements = form.getElementsByTagName(tagName);
       for (var j = 0; j < tagElements.length; j++)
         elements.push(tagElements[j]);
@@ -627,7 +627,7 @@
   },
 
   disable: function(form) {
-    var elements = Form.getElements(form);
+    var elements = Form1.getElements(form);
     for (var i = 0; i < elements.length; i++) {
       var element = elements[i];
       element.blur();
@@ -636,7 +636,7 @@
   },
 
   enable: function(form) {
-    var elements = Form.getElements(form);
+    var elements = Form1.getElements(form);
     for (var i = 0; i < elements.length; i++) {
       var element = elements[i];
       element.disabled = '';
@@ -645,7 +645,7 @@
 
   focusFirstElement: function(form) {
     var form = $(form);
-    var elements = Form.getElements(form);
+    var elements = Form1.getElements(form);
     for (var i = 0; i < elements.length; i++) {
       var element = elements[i];
       if (element.type != 'hidden' && !element.disabled) {
@@ -660,11 +660,11 @@
   }
 }
 
-Form.Element = {
+Form1.Element = {
   serialize: function(element) {
     var element = $(element);
     var method = element.tagName.toLowerCase();
-    var parameter = Form.Element.Serializers[method](element);
+    var parameter = Form1.Element.Serializers[method](element);
     
     if (parameter)
       return encodeURIComponent(parameter[0]) + '=' +
@@ -674,24 +674,24 @@
   getValue: function(element) {
     var element = $(element);
     var method = element.tagName.toLowerCase();
-    var parameter = Form.Element.Serializers[method](element);
+    var parameter = Form1.Element.Serializers[method](element);
     
     if (parameter)
       return parameter[1];
   }
 }
 
-Form.Element.Serializers = {
+Form1.Element.Serializers = {
   input: function(element) {
     switch (element.type.toLowerCase()) {
       case 'submit':
       case 'hidden':
       case 'password':
       case 'text':
-        return Form.Element.Serializers.textarea(element);
+        return Form1.Element.Serializers.textarea(element);
       case 'checkbox':  
       case 'radio':
-        return Form.Element.Serializers.inputSelector(element);
+        return Form1.Element.Serializers.inputSelector(element);
     }
     return false;
   },
@@ -725,7 +725,7 @@
 
 /*--------------------------------------------------------------------------*/
 
-var $F = Form.Element.getValue;
+var $F = Form1.Element.getValue;
 
 /*--------------------------------------------------------------------------*/
 
@@ -753,17 +753,17 @@
   }
 }
 
-Form.Element.Observer = Class.create();
-Form.Element.Observer.prototype = (new Abstract.TimedObserver()).extend({
+Form1.Element.Observer = Class.create();
+Form1.Element.Observer.prototype = (new Abstract.TimedObserver()).extend({
   getValue: function() {
-    return Form.Element.getValue(this.element);
+    return Form1.Element.getValue(this.element);
   }
 });
 
-Form.Observer = Class.create();
-Form.Observer.prototype = (new Abstract.TimedObserver()).extend({
+Form1.Observer = Class.create();
+Form1.Observer.prototype = (new Abstract.TimedObserver()).extend({
   getValue: function() {
-    return Form.serialize(this.element);
+    return Form1.serialize(this.element);
   }
 });
 
@@ -791,7 +791,7 @@
   },
   
   registerFormCallbacks: function() {
-    var elements = Form.getElements(this.element);
+    var elements = Form1.getElements(this.element);
     for (var i = 0; i < elements.length; i++)
       this.registerCallback(elements[i]);
   },
@@ -825,17 +825,17 @@
   }
 }
 
-Form.Element.EventObserver = Class.create();
-Form.Element.EventObserver.prototype = (new Abstract.EventObserver()).extend({
+Form1.Element.EventObserver = Class.create();
+Form1.Element.EventObserver.prototype = (new Abstract.EventObserver()).extend({
   getValue: function() {
-    return Form.Element.getValue(this.element);
+    return Form1.Element.getValue(this.element);
   }
 });
 
-Form.EventObserver = Class.create();
-Form.EventObserver.prototype = (new Abstract.EventObserver()).extend({
+Form1.EventObserver = Class.create();
+Form1.EventObserver.prototype = (new Abstract.EventObserver()).extend({
   getValue: function() {
-    return Form.serialize(this.element);
+    return Form1.serialize(this.element);
   }
 });
 
@@ -1033,6 +1033,4 @@
     target.style.top    = offsets[1] + 'px';
     target.style.left   = offsets[0] + 'px';
     target.style.width  = source.offsetWidth + 'px';
-    target.style.height = source.offsetHeight + 'px';
-  }
-}
+    target.style.height = source.off
\ No newline at end of file

Re: RE: Re: "Form" is not a constructor

by Paul King :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here is a file which exhibits the error - just click on the button - change Form to Form1 in 2 places and it no longer breaks:

<html>
<head>
<script type="text/javascript">
<!--
var Form = {
  getElements: function(form) {
    form = $(form);
    var elements = new Array();
    for (tagName in Form.Element.Serializers) {
      var tagElements = form.getElementsByTagName(tagName);
      for (var j = 0; j < tagElements.length; j++)
        elements.push(tagElements[j]);
    }
    return elements;
  }
}
function validate() {
    currentForm = document.getElementById('formId');
    currentForm.field1.value="fred";
    return false;
}
// -->
</script>
</head>
<body>
   <form id='formId' name='formName'>
     <input type="text" name="field1" value="barney">
     <input type="button" type="submit" id="submit" onClick="validate()">
   </form>
</body>
</html>

If it helps, here is a WebTest script for clicking the link:

    <target name="main">
        <property name="testfile" location="checkJavaScript.html"/>
        <webtest name="prototype.js bug">
            <config
                    summary="true"
                    saveresponse="true"
                    showhtmlparseroutput="false"/>
            <steps>
                <invoke url="file:///${testfile}"/>
                <clickButton htmlId="submit" />
                <verifyInputField name="field1" value="fred"/>
            </steps>
        </webtest>
    </target>

Re: "Form" is not a constructor

by Marc Guillemot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, I've understood the problem: Form is newly defined and when we want to
create the JS object for the form trying to call our JS host object through its
constructor, it has been replaced by the local "Form" object.

This will be quite simple to fix, just using an other name for the internal use
of the object. I guess that the problem occurs with other of htmlunit's host
classes and I will try to check them all.

Marc.



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Re: "Form" is not a constructor

by mraible :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Please let me know when this is fixed in CVS - I'd be more than happy to test.

Re: "Form" is not a constructor

by Marc Guillemot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

mraible (sent by Nabble.com) wrote:
> Please let me know when this is fixed in CVS - I'd be more than happy to
> test.

sure.
I thought that I could fix it this evening but it is a bit more
complicated as I thougt, I will post a message when it is fixed (I hope
this week).

Marc.


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Re: "Form" is not a constructor

by Marc Guillemot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Matt,

this should now work for Form.

The work needs to be extended to definitely avoid name conflicts. I
won't ship a new htmlunit jar to webtest until this is done but you can
already build one by yourself from htmlunit's public CVS and use it in
place of the provided one in the latest webtest build.

Marc.

mraible (sent by Nabble.com) wrote:
> Please let me know when this is fixed in CVS - I'd be more than happy to
> test.
> ------------------------------------------------------------------------
> View this message in context: Re: "Form" is not a constructor
> <http://www.nabble.com/%22Form%22-is-not-a-constructor-t716240.html#a2279743>
> Sent from the HtmlUnit - General
> <http://www.nabble.com/HtmlUnit---General-f2599.html> forum at Nabble.com.



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Re: "Form" is not a constructor

by mraible :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I checked out and built from CVS, but no luck - the error is still there.  I suspect SF's anonymous CVS hasn't synchronized yet? Is there anyway to post a snapshot or send me the JAR? mraible AT Gmail.

Thanks,

Matt

Re:

by Marc Guillemot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

mraible (sent by Nabble.com <lists <at> nabble.com> writes:

>
>
> I checked out and built from CVS, but no luck - the error is still there.  I
suspect SF's anonymous CVS hasn't synchronized yet? Is there anyway to post a
snapshot or send me the JAR? mraible AT Gmail.
> Thanks,
> Matt
>
> View this message in context: Re: "Form" is not a constructor
> Sent from the HtmlUnit - General forum at Nabble.com.
>


I've checked through the public ViewCVS and the change seems now to be
available.

Generally you can use the diff that is automatically posted to the dev mailing
list after each commit and apply it locally when you don't want to wait for the
public CVS to be updated.

Marc.



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Re: Re:

by mraible :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Marc - works great!

Re: Re:

by Kaleinani :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am running into this same problem and am wondering if the newest version of HtmlUnit (1.8 released in February) had this fix.  I even tried building from CVS (now a 1.9 prerelease) with no luck.  If possible, however, is there some modifications that I can do myself so that I can still use HtmlUnit 1.7?  I have a bunch of other test cases that have now deprecated methods and would like to avoid a refactor.

Re: Re:

by Marc Guillemot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

if you want to delay your refactoring work, you have to avoid the use of a js variable named Form... or backport the fix for this problem to htmunit 1.7. Nevertheless I guess that it is less work to upgrade to htmlunit 1.8 and this makes you ready to benefit from the next fix that you will need ;-)

Marc.