How to submit a form using Selenium Webdriver?

Selenium Webdriver provides an inbuilt function called submit() which is used to submit a form.
Lets take an example of any login screen in which one has to enter username/password and click on login button. Instead of clicking on login button, we will going to use submit() function.

Webdriver code to submit a login form is as follows :-

//Enter username
driver.findElement(By.id("usrnm")).sendKeys("contact.automateapps@gmail.com");

//Enter password
driver.findElement(By.id("psswrd")).sendKeys("password");

//submit form
driver.findElement(By.id("password")).submit();

/* In order to submit a form, you can use any element of a form. 
WebDriver will find the form for us from the element. 
In the above code, id of password input box is used to identify a form.

*/

Leave a Reply

Your email address will not be published. Required fields are marked *