Selenium Webdriver submit() vs click()

CosminO picture CosminO · Jul 8, 2013 · Viewed 136.7k times · Source

Let's say I have an input in a form (looks like a button and interacts like a button) which generates some data (well, the server generates the data based on the form parameters, but for the user, the button does it :) )based on the parameters in the form.

When I use click(), the whole process hangs (it actually freezes, no exceptions or errors).

From the Selenium website:

// Now submit the form. WebDriver will find the form for us from the element
element.submit();

So WebDriver has a submit() method. Is there any difference, logic wise, between using a click() on a button or submit() ?

Answer

Dan2.0 picture Dan2.0 · Jul 8, 2013

The submit() function is there to make life easier. You can use it on any element inside of form tags to submit that form.

You can also search for the submit button and use click().

So the only difference is click() has to be done on the submit button and submit() can be done on any form element.

It's up to you.

http://docs.seleniumhq.org/docs/03_webdriver.jsp#user-input-filling-in-forms