Overview:
This script demonstrates a basic automation flow for filling out web forms using data from an Excel file. It handles finding the next available row, mapping form fields, submitting the form, and updating the Excel sheet. The try-except block ensures error handling, and the finally block closes the WebDriver instance.
Steps:
Importing Libraries:
The code begins by importing necessary libraries: webdriver for browser automation with Selenium, openpyxl for working with Excel files, and time for adding delays.
get_data_from_excel Function:
This function reads data from an Excel file and initializes an empty dictionary data.
Loop to Find Next Available Row:
The function uses a while loop to find the next available row where the status is not "Done" in column F. If the status is not "Done," the loop breaks, and it moves to the next steps.
Reading Data from Excel:
If the status is not "Done," the function extracts column names and values from the specified row and creates a dictionary (data) with column names as keys and corresponding values. The function returns both the data and the updated row number.
fill_form_with_excel_data Function:
This function fills out a web form using data from the Excel file.
It opens a Chrome browser, navigates to a web page, and sleeps for 2 seconds.
Filling Form and Updating Excel:
The function calls get_data_from_excel to get employee data and the updated row number.If employee data is available, it maps form field names to Excel column names and fills in the form fields using Selenium. After submitting the form, it updates the status in the Excel sheet to "Done" for the processed row.
Main Execution:
The script sets an initial row_number and calls the fill_form_with_excel_data function.
Note: I created a simple form using Flask framework, you can create your own too. You can find the complete python file here: https://github.com/Aaminah27/Python-Scripts/blob/main/form-automation.py








Comments
Post a Comment