I’ve been using Selenium and the Chrome web driver for some time to test my web forms, and this week, I’ve created a video on doing this for a web form and showing you how this works with a standard web form.
Now Selenium is a python library and you access the chrome web driver by setting your python and your webdriver to be on the path for me this is simple I have a pathed directory where everything within it is automatically on path on my Windows 11 Machine
The example used in the tutorial is below and the form plugin in this instance was SureForms.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
# Set up the Selenium WebDriver
driver = webdriver.Chrome()
# Open the target form page
driver.get("https://forms.wpcode.dev/contact")
# Wait for the form to load
time.sleep(3)
# Fill in the "Name" field
name_field = driver.find_element(By.ID, "srfm-input-0665c111-lbl-TmFtZQ")
name_field.send_keys("John Doe")
# Fill in the "Email" field
email_field = driver.find_element(By.ID, "srfm-email-b3386c12-lbl-RW1haWw")
email_field.send_keys("john.doe@example.com")
# Fill in the "Phone Number" field
phone_field = driver.find_element(By.ID, "srfm-phone-96461465-lbl-UGhvbmUgTnVtYmVy")
phone_field.send_keys("1234567890")
# Select an option from the dropdown
dropdown = driver.find_element(By.ID, "tomselect-1-ts-control")
dropdown.click() # Open the dropdown
# Wait for the dropdown to open
time.sleep(1)
# Select the first option in the dropdown
option = driver.find_element(By.ID, "tomselect-1-opt-1")
option.click()
# Fill in the "Message" box
message_box = driver.find_element(By.ID, "srfm-textarea-bb1d9092-lbl-TWVzc2FnZQ")
message_box.send_keys("This is a sample message.")
# Submit the form
submit_button = driver.find_element(By.ID, "srfm-submit-btn")
submit_button.click()
# Wait for the result and close the browser
time.sleep(5)
driver.quit()
Python
This 48 lines of code allows for a totally automatted testing, how i run my testing is to have a windows schedule to run a bat file (below) which then runs the entire of the python (py) files in the directory to test the individual forms.
@echo off
for %%f in (*.py) do (
echo Running %%f
python "%%f"
)
echo All scripts completed!
pause
BAT (Batchfile)
You can watch the YouTube Video here:
If your more of a visual builder you may want to give packages ago and in the previous video to this one you can watch me build a “package” live for the same webform why not sign up for packages its quick and easy to get the hang of and there is setup but its a “no code” solution.