Using webdriver on a page with a form that runs javascript onsubmit seems to fail

41 views
Skip to first unread message

Theo

unread,
Dec 28, 2009, 6:29:24 PM12/28/09
to webdriver
Hi,

I am relatively new with WebDriver. I have a webape for which I am
trying to write a test. The webpage is a form that has two fields a
hidden field and a text area that allows the user to enter an email
address. The form has an onsubmit attribute that calls a javascript
method. The javascript method copies the email address to the hidden
field.

I tried both HtmlUnit (with javascript enabled) and the Firefox
drivers and it seems that the hidden field does not get populated when
I run the test with webdriver. When I type it in on firefox, hidden
field gets populated.

Any ideas as to why this is happening?

Thanks,

--
Theo

Daniel Wagner-Hall

unread,
Dec 28, 2009, 7:41:36 PM12/28/09
to webd...@googlegroups.com

Could you post your test code, and if possible the HTML and javascript
you're testing against?

Ahmed Ashour

unread,
Dec 29, 2009, 3:47:48 AM12/29/09
to webd...@googlegroups.com
Hi Theo,
 
Please provide your minimal html/js/java test case, so we can investigate.
 
Yours,
Ahmed
----
Blog: http://asashour.blogspot.com

From: Theo <ther...@gmail.com>
To: webdriver <webd...@googlegroups.com>
Sent: Tue, December 29, 2009 2:29:24 AM
Subject: [webdriver] Using webdriver on a page with a form that runs javascript onsubmit seems to fail
--

You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.



Simon Stewart

unread,
Dec 29, 2009, 8:25:04 AM12/29/09
to webd...@googlegroups.com
I suspect that your hidden field gets updated when the focus shifts
from the textfield. If that's the case, then you may not see the
expected behaviour when calling the "submit" method (though you
should) Does your test look a little like this?

WebElement textField = driver.findElement(By.id("foo"));
textField.sendKeys("cheese");
textField.submit();

Regards,

Simon

On Mon, Dec 28, 2009 at 11:29 PM, Theo <ther...@gmail.com> wrote:

> --
>
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.

> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

Theo

unread,
Dec 30, 2009, 6:49:00 PM12/30/09
to webdriver
In the process of re-creating the page in order to post the code here,
I figured out the problem.

The form in question had an input field of type "image", my test code
was calling `submit()' on a different element. That seems to cause the
from submission but without any events that would trigger the script
specified with the `onsubmit' attribute.

If my reasoning here is wrong please let me know, I now have a pretty
trimmed down version of the page and code and how to reproduce the
behavior.

Thanks.

--
Theo

On Dec 29, 5:25 am, Simon Stewart <simon.m.stew...@gmail.com> wrote:
> I suspect that your hidden field gets updated when the focus shifts
> from the textfield. If that's the case, then you may not see the
> expected behaviour when calling the "submit" method (though you
> should) Does your test look a little like this?
>
> WebElement textField = driver.findElement(By.id("foo"));
> textField.sendKeys("cheese");
> textField.submit();
>
> Regards,
>
> Simon
>

Jason Leyba

unread,
Dec 30, 2009, 7:14:25 PM12/30/09
to webd...@googlegroups.com
The submit() command may be used on any element in a form, so if you
call it on an element that your event handlers are not attached to,
you won't get the expected behavior.  If the problem is that the
form's onsubmit handler isn't being called, then we definitely have a
bug and would appreciate a reproducible test case :)

-- Jason

Daniel Wagner-Hall

unread,
Jan 1, 2010, 6:26:33 AM1/1/10
to webd...@googlegroups.com
Also possible that the onsubmit is being fired by the element, not the
form, and not bubbling properly for some reason, as we had for select
elements... Will check at some point...

Daniel Wagner-Hall

unread,
Jan 1, 2010, 12:03:23 PM1/1/10
to webd...@googlegroups.com
Yes, this is definitely a bug in WebDriver, I have filed it at
http://code.google.com/p/selenium/issues/detail?id=300

I will fix this in the next few days :)

Therapon Skotiniotis

unread,
Jan 4, 2010, 12:40:55 PM1/4/10
to webd...@googlegroups.com
Excellent. We have a way of getting the forms that use this feature
working in webdriver. Having the fix as well would be even better.
I'll update the ticket with the example code.

Thanks

--
Theo

Reply all
Reply to author
Forward
0 new messages