From: <ddk...@ki...> - 2004-06-23 23:44:21
|
If I had to guess, your calling of 'test.getFormByName("myYear").submit()' is probably not what a real user would do if they were using the form. This method submits the form without "clicking" any "buttons" or changing anything else on the form. (It mimics what JavaScript would do if you called submit() on a form object within a JS method.) What you probably want to do is mimic more closely what the actual user would do, i.e., if the form was automatically submitted when the user picked a value out of a SELECT list, then your htmlunit code should do the same thing (pick a value out of a select list), and expect the JavaScript to be run the same way as it would in a browser. To diagnose the problem further, a reduced test case with HTML and JavaScript would be helpful. Finally, the "DomNode has not been set for this SimpleScriptable" error message means that the JavaScript engine (Rhino) tried to access an object of type SimpleScriptable that wasn't linked to a corresponding DomNode object. When Htmlunit loads a web page, it parses the HTML into a DOM tree made up of DomNodes. Each DomNode may potentially have a SimpleScriptable object associated with it (and vice-versa; it's a bi-directional relationship). However, the SimpleScriptable objects are generally initialized in a lazy manner because they are only used by Rhino, and most pages won't access every single html element in a web page during the life of the page. http://www.mozilla.org/rhino/ I have seen bugs (see example link below) where the source code assumes that the SimpleScriptable object has been initialized when, in fact, it has not. [ 916316 ] Fix use of this.form in JavaScript events of form elements http://sourceforge.net/tracker/index.php?func=detail&aid=916316&group_id=47038&atid=448266 Your issue may or may not be related to a similar issue, but a test case is needed to determine that. Dave On Wed, Jun 23, 2004 at 02:55:45PM -0700, Elise Lebeau wrote: > I'm evaluating htmlunit and am running into a pretty basic problem. I can't > submit a form that has a javascript action. Do I need to do some init for > JavaScript to work? > I am using 1.3pre and this is my code: > > final WebClient webClient = new WebClient(); > final URL url = new URL(url); > > final HtmlPage page1 = (HtmlPage)webClient.getPage(url); > final List list = page1.getFrames(); > final HtmlFrame frame2 = (HtmlFrame)list.get(1); > final HtmlPage test = (HtmlPage)frame2.getEnclosedPage(); > test.getFormByName("myYear").submit(); > > this is the stack: > com.gargoylesoftware.htmlunit.ScriptException: DomNode has not been set for > this SimpleScriptable: com.gargoylesoftware.htmlunit.javascript.host.Select > at > com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScript > Engine.java:264) > at > com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(Html > Page.java:700) > at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:156) > at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:130) > [...] |