Difference between element click and submit

1,090 views
Skip to first unread message

angshu

unread,
Jul 19, 2011, 8:22:47 AM7/19/11
to Selenium Users
Hi, I want to know how Webdriver deals with a button's click/submit
events. When should we call element's submit or click?

e.g. consider the following test
*****************************************
org.openqa.selenium.WebDriver driver = new
org.openqa.selenium.firefox.FirefoxDriver();
driver.get("http://net.tutsplus.com/demos/contactform/");
driver.findElement(By.id("name")).sendKeys("test");
driver.findElement(By.id("email")).sendKeys("te...@gmail.com");
driver.findElement(By.id("phone")).sendKeys("098765432");
driver.findElement(By.id("submit_btn")).submit();
junit.framework.Assert.assertTrue(browser.findElement(By.id("checkmark")).isDisplayed());
*****************************************
If I would change, the element.submit() to click() in the 6th line
above, the test passes. Calling submit() doesnt seem to work.
What does webdriver do in the background?
Does it call element's form.submit() method? What would be the effect
if I enter on an <input> to trigger the default form submit action?

Jeff

unread,
Jul 19, 2011, 4:37:50 PM7/19/11
to seleniu...@googlegroups.com
submit() is for forms, click() is for buttons.
 
driver.findElement(By.tagName("form")).submit();


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--
I ♥ DropBox !! 

Luke Inman-Semerau

unread,
Jul 19, 2011, 5:29:40 PM7/19/11
to seleniu...@googlegroups.com
It also submits the form on any form element (input, textarea, select) -

driver.findElement(By.cssSelector("input#username")).submit();

angshu

unread,
Jul 20, 2011, 6:47:29 AM7/20/11
to Selenium Users
Hi, thanks for you replies.
I do know that submit() can be invoked on the form. Or if a form has a
default submit then "enter" would submit the underlying form.
Like on a web page, if I have multiple forms and each submits to
different URLs, then "enter" on individual elements (like input) would
submit the element's parent form.

However, I was wondering how WebDriver deals with such
WebElement.submit() calls.
Does it introspect on the element it is called and then calls the
parentForm.submit()?

Why I ask is that, on some browsers button.submit() works perfectly
for the example URL I posted.
e.g. With IE9, Win7, Se 2.0.1.0 the same script with button.submit()
works.
on FF3.6, FF5, Max OSX, Se 2.0 it doesn't.
regards
~angshu





On Jul 20, 2:29 am, Luke Inman-Semerau <luke.seme...@gmail.com> wrote:
> It also submits the form on any form element (input, textarea, select) -
>
> driver.findElement(By.cssSelector("input#username")).submit();
>
>
>
>
>
>
>
> On Tue, Jul 19, 2011 at 1:37 PM, Jeff <predato...@gmail.com> wrote:
> > submit() is for forms, click() is for buttons.
>
> > driver.findElement(By.tagName("form")).submit();
>
> > On Tue, Jul 19, 2011 at 6:22 AM, angshu <angshuonl...@gmail.com> wrote:
>
> >> Hi, I want to know how Webdriver deals with a button's click/submit
> >> events. When should we call element's submit or click?
>
> >> e.g. consider the following test
> >> *****************************************
> >> org.openqa.selenium.WebDriver driver = new
> >> org.openqa.selenium.firefox.FirefoxDriver();
> >> driver.get("http://net.tutsplus.com/demos/contactform/");
> >> driver.findElement(By.id("name")).sendKeys("test");
> >> driver.findElement(By.id("email")).sendKeys("t...@gmail.com");
> >> driver.findElement(By.id("phone")).sendKeys("098765432");
> >> driver.findElement(By.id("submit_btn")).submit();
>
> >> junit.framework.Assert.assertTrue(browser.findElement(By.id("checkmark")).isDisplayed());
> >> *****************************************
> >> If I would change, the element.submit() to click() in the 6th line
> >> above, the test passes. Calling submit() doesnt seem to work.
> >> What does webdriver do in the background?
> >> Does it call element's form.submit() method? What would be the effect
> >> if I enter on an <input> to trigger the default form submit action?
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Selenium Users" group.
> >> To post to this group, send email to seleniu...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> selenium-user...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/selenium-users?hl=en.
>
> > --
> > Jeff Vincent
> > predato...@gmail.com
> > See my LinkedIn profile at:
> >http://www.linkedin.com/in/rjeffreyvincent
> > I ♥ DropBox <http://db.tt/9O6LfBX> !!

Luke Inman-Semerau

unread,
Jul 20, 2011, 9:04:29 AM7/20/11
to seleniu...@googlegroups.com
Yes, submit finds the element's parent form and submit's it.

If this is not working for you, please provide a reproducible test case with all relevant version numbers and enter it in the issues list:
http://code.google.com/p/selenium/issues/list


-Luke

Reply all
Reply to author
Forward
0 new messages