- Home
- Introduction
- Installation
- Browser Navigation
- Identify Single Element
- Identify Multiple Elements
- Explicit and Implicit Wait
- Pop-ups
- Backward and Forward Navigation
- Cookies
- Exceptions
- Action Class
- Create a Basic Test
- Forms
- Drag and Drop
- Windows
- Alerts
- Handling Links
- Handling Edit Boxes
- Color Support
- Generating HTML Test Reports in Python
- Read/Write data from Excel
- Handling Checkboxes
- Executing Tests in Multiple Browsers
- Headless Execution
- Wait Support
- Select Support
- JavaScript Executor
- Chrome WebDriver Options
- Scroll Operations
- Capture Screenshots
- Right Click
- Double Click
- Selenium Webdriver Useful Resources
- Selenium WebDriver - Quick Guide
- Selenium WebDriver - Useful Resources
- Selenium WebDriver - Discussion
Selenium Webdriver - Forms
Selenium webdriver can be used to submit a form. A form in a page is represented by the <form> tag. It contains sub-elements like the edit box, dropdown, link, and so on. Also, the form can be submitted with the help of the submit method.
The syntax for forms is as follows −
src = driver.find_element_by_css_selector("#draggable")
src.submit()
Let us see the html code of elements within the form tag.
On submitting a form with the above html code, the below alert message is displayed.
Code Implementation
The code implementation for submitting a form is as follows −
from selenium import webdriver
from selenium.webdriver.common.alert import Alert
driver = webdriver.Chrome(executable_path='../drivers/chromedriver')
#implicit wait time
driver.implicitly_wait(5)
#url launch
driver.get("https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm")
#identify element within form
b = driver.find_element_by_name("firstname")
b.send_keys('Tutorialspoint')
e = driver.find_element_by_name("lastname")
e.send_keys('Online Studies')
#submit form
e.submit()
# instance of Alert class
a = Alert(driver)
# get alert text
print(a.text)
#accept alert
a.accept()
#driver quit
driver.quit()
Output
The output shows the message - Process with exit code 0 meaning that the above Python code executed successfully. Also, the Alert text - You are submitting information to an external page.
Are you sure?
The above message gets printed in the console.
Advertisements