Submit Form in Selenium Python

Selenium – Submit Form

To submit a form in Selenium Python, you can call the submit() method on the form element.

In this tutorial, you will learn how to find and submit a form in Selenium Python, with an example program.


In this example, we shall load the URL with webpage index.html with contents shown in the following.

  function someFunction(){
    console.log('form submitted.');
  <h1>My Sample Form</h1>
  <form id="myform" onsubmit="someFunction()">
    <label for="firstname">First name:</label>
    <input type="text" id="myfirstname" name="firstname"><br><br>
    <label for="lastname">Last name:</label>
    <input type="text" id="mylastname" name="lastname"><br><br>
    <label for="age">Age:</label>
    <input type="text" id="myage" name="age"><br><br>
    <input type="submit" value="Submit">

In the following program, we initialize a Chrome webdriver, load URL for a webpage with a form element that has three input text fields. We shall find the form using id attribute, and then submit the form.

In the index.html, upon form submission, someFunction() is called, which prints a message to console, and then prevents the default action of redirecting the page.

Python Program

from selenium import webdriver
from import ChromeDriverManager
from import Service as ChromeService
from import By
import time

# Setup chrome driver
service = ChromeService(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
driver.set_window_size(500, 700)

# Navigate to the url

# Find form element
myform = driver.find_element(By.ID, 'myform')

# Submit my form

# Wait for 20s to observe console log

# Close the driver


Python Selenium - Submit Form


In this Python Selenium tutorial, we learned how to submit a form in the document, using submit() method, with the help of examples.

Quiz on Selenium

Q1. What is Selenium Python used for?

Not answered

Q2. What is the method used to navigate back to the previous page in Selenium Python?

Not answered

Q3. Which of the following is not a commonly used assertion method in Selenium Python?

Not answered

Q4. What is the method used to switch to a different frame in Selenium Python?

Not answered

Q5. What is the method used to select a value from a drop-down list in Selenium Python?

Not answered