Tuesday 8 July 2014

Difference between Click() and Submit() in Selenium



-> Both click() and submit() both are used to click Button in Web page.

-> Selenium Webdriver has one special method to submit any form and that method name Is submit(). submit() method works same as clicking on submit button.


When to use .click() method :

-> You can use .click() method to click on any button.There is no restriction for click buttons.

-> That means element's type = "button" or type = "submit", .click() method will works for both.

-> If button is inside <form> tag or button is outside <form> tag, the click() method will work.



When to use .submit() method :

-> we can use .submit() method for only submit form after click on button.

-> That means element's type = "submit" and button should be inside <form> tag, then only submit() will work.

-> if element's type = "button" means submit() will not work.

-> If button outside of the <form> tag means submit() will not work


For Example, Submit() will work if submit button should be inside <form> tag and element type="submit" as below

<form>
<input id="submitbutton" name="submitbutton" type="submit" value="Next step" class="g-button g-button-submit">
</form>


But click() method will work for all  buttons in webpage with out any restrictions.

5 comments:

  1. Tried the same for facebook signup. Even for type submit, inside form also submit() is not working.

    ReplyDelete
  2. Finally a great explanation to this question. Thanks mate.

    ReplyDelete
  3. Your posts never fail to remind me of the importance of gratitude in our lives. Clicks Per Second is like a hidden gem for gamers, and I couldn't resist recommending it to someone as passionate as you!

    ReplyDelete
  4. I'm grateful for the sense of community and belonging your blog provides! Gear up for some laugh-out-loud moments and heart-pounding action in Funny Shooter 2 Unblocked - it's the ultimate gaming thrill!

    ReplyDelete