form field named "submit" causes "submit" method to not work

84 views
Skip to first unread message

peto

unread,
May 14, 2008, 1:40:10 PM5/14/08
to Watir General
Is there a known reason that naming a form field "submit" would cause
the Watir form submit method to not actually submit?

Using the "click" method works (as can be seen by the query string)
but using the "submit" method doesn't appear to do anything unless I
change the name "submit" to something else (e.g. "submit1", etc.).
Perhaps it is noteworthy that the "flash" method does not appear to be
affected in a similar manner.

sample html page
###############
<html>
<head><title>Title</title></head>
<body>
<form name="formname" action="" method="GET">
<input type="text" name="flash">
<input type="text" name="submit">
<input type="submit" name="go">
</form>
</body>
</html>
###############

sample Watir code
(apologies in advance for using the generic "example.com")
###############
require 'watir'
ie = Watir::IE.start('http://example.com/')
ie.form(:name, 'formname').flash
ie.form(:name, 'formname').submit
###############



Using irb the submit method returns what appears to be a response time
irb(main):004:0> ie.form(:name, 'formname').submit
=> 0.203

ruby version: ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]
Watir::IE::VERSION: 1.5.4.1263

Regards,
John

marekj

unread,
May 14, 2008, 4:08:34 PM5/14/08
to watir-...@googlegroups.com
 A quick look at Form.submit method shows that it delgates to
@ole_object.submit

in this case I think @ole_object is the form itself.
So like in a way it invokes form.submit();

let's say you have a form

<form id="gform" name="g" action="http://google.com/" method="GET">
<input type="text" name="q" value="watir" />
<input type="text" name="submit" value="the submit thing" />
<input type="submit" value="clickit" />
</form>

and you do this:
ie.form(:id, 'gform').document.invoke('submit')
it will return an ole object in irb.
and if you do this
ie.form(:id, 'gform').document.invoke('submit').value
it will reutnr 'the submit thing' value of the input named 'submit'.

The short exlanation I can invent is this:
running this code
ie.form(:id, 'gform').document.invoke('submit')

should invoke the the form's sumbit method unless there is an element named submit that will steal the call.

marekj

www.testr.us | semantic test objects modeling in watir
--

peto

unread,
May 23, 2008, 11:19:33 AM5/23/08
to Watir General
Thanks for the clarification.

Are "namespace" collisions such as this common in Watir and/or Ruby?
Is there syntax that would prevent an element name from overriding a
method call?
Perhaps I'm failing to grasp something about Watir and/or Ruby and/or
the "Ruby way" here, but it seems odd that a mere element name can
break some other method. After all, the next version of Watir may
have a new method "foo" (though perhaps not for the ole object), that
would conflict with existing elements named "foo".

John

marekj

unread,
May 23, 2008, 7:48:43 PM5/23/08
to watir-...@googlegroups.com
I don't think this issue has nothing to do with Watir, Ruby or the Ruby Way.
It is simply a convention in HTML to use name='submit' for an element in 'form' that will actually execute
usually it is expressed as <input type=submit name=sumbmit .... >
If on a winter's night or summer's early wee wee hours a developer decides to name an element in the form with 'sumbit' which actually does not 'submit' then it is the moment where a certain convention is broken.
Yes, it may be a bug but a trivial bug IMHO, leave 'subimt' names to elements that submit and ye shall have less debugging to do.


marekj

www.testr.us | semantic test objects modeling in watir



--

Bret Pettichord

unread,
Jun 18, 2008, 3:33:34 PM6/18/08
to watir-...@googlegroups.com
John,

This was a bug in Watir. I logged this in Jira
http://jira.openqa.org/browse/WTR-223

I also just committed a fix to trunk. It will be included in Watir 1.5.7.

Thank you for your report and your persistent curiousity.

Bret

marekj

unread,
Jun 19, 2008, 9:17:10 AM6/19/08
to watir-...@googlegroups.com
Ooops... I made a wrong assumption in this then, sorry.
Glad you fixed the bug.

marekj
Reply all
Reply to author
Forward
0 new messages