From: Marc G. <mgu...@ya...> - 2005-03-16 08:59:55
|
From the javadoc of HtmlForm#submit(): "Submit this form to the appropriate server as if it had been submitted by javascript - ie no submit buttons were pressed. Note that because we are simulating a javascript submit, the onsubmit handler will not get executed." In a real browser you won't call submit on a form, you will click a submit button. Just do the same with htmlunit and your javascript will be executed. Marc. Kent Tong wrote: > Hi, > > It seems that the onsubmit handler is not called when I call > submit() on the form. Here is a test html file: > > <html> > <body> > <script language="JavaScript"><!-- > function foo() { > alert('ddd'); > } > // --></script> > <form name="form1" onsubmit="foo()"> > <input type="Submit" name="OK" value="OK"/> > </form> > </body> > </html> > > The test case below fails: > > public class OnsubmitTest extends TestCase { > public void testOnSubmit() throws Exception { > WebClient client = new WebClient(); > CollectingAlertHandler handler = new CollectingAlertHandler(); > client.setAlertHandler(handler); > URL url = new URL("http://localhost:8080/TDDCalc/Test.html"); > HtmlPage page = (HtmlPage) client.getPage(url); > HtmlForm form = (HtmlForm) page.getAllForms().get(0); > form.submit(); > assertEquals(handler.getCollectedAlerts().size(), 1); > } > } > > If I use a real browser, it does show the alert. Any idea? > TIA! > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > |