Use this code to fill in a google form.
You can also use this to automate any browser task.
When virtual learning started due to covid, we had a google form to fill in for attendance. At that time, I felt that it was pointless to fill-in and submit the same form everyday. So then, I decided to use python and automate this task. When I first started this, it only worked with 1 browser. When I tested it on a differet browser, I realized that it had performed a bit differently. Now it has support for 3 different browsers.
Before using the code, note that selemium has been updated and xpaths are used differently. Now you would probably use
from selenium.webdriver.common.by import By
...
driver.find_element(By.XPATH, '//*[@id="Email"]')
- Download Python along with pip (you will need to do this manually during the installation of python)
- Open cmd (command prompt) and type
pip install selenium
- Download any code editor that can run python. I use VS code with a python extension.
- Download geckodriver (Mozilla Firefox), chromedriver (Chrome) or msedgedriver (Microsoft Edge) and place it in some directory.
- After you install a driver go to the corresponding folder
- Download the files
- Edit
config.json
accordingly - You might need to change the email in the
main.py
file to add a number depending on how your email systems work for example from:
{firstName}.{lastName}@gmail.com
to{firstName}.{lastName}[email protected]
you might need to change the email depending on the form and your domain. - Run the
main.py
file
-
You could open the file with a normal text editor, and run the file from the command line.
-
If you want to use a specific driver, you need the corresponding browser.
To find an elements xpath:
First open the inspector
Then select the element
Finally right click, select copy, and select xpath
All the xpaths were fetched from Google Chrome but the examples use Mozilla Firefox