Ajay Mandal
Ajay Mandal

Reputation: 51

Filling Webform using selenium from excel via python

I want to fill webforms using selenium web driver in python language. thats not a tough task indeed but I am unable to find out how can fill the webform when the data must be taken from excel file.

I have tried selenium to fill webform that is possible and easy

rom selenium import webdriver

driver = webdriver.Chrome("C:\\chrome_driver\\chromedriver_win32\\chromedriver.exe")
driver.get("https://admin.typeform.com/signup")
driver.find_element_by_id("signup_owner_alias").send_keys("Bruce Wayne")
driver.find_element_by_id("signup_owner_email").send_keys("[email protected]")
driver.find_element_by_id("signup_terms").click()
driver.find_element_by_id("signup_owner_language").click()

Upvotes: 2

Views: 2057

Answers (1)

Sosthenes Kwame Boame
Sosthenes Kwame Boame

Reputation: 373

You can use the pandas library to fetch the data from your excel sheet. If you don't have it installed, you install it with pip: pip install pandas.

Below is an example of how data is fetched from an excel sheet using pandas.

import pandas as pd

df = pd.read_excel('centuries.xls')

sheet_years = df['Year']

for year in sheet_years:
    print(year)

Basically, we fetched the excel sheet (centuries.xls) using the read_excel() method. Then we saved one of the columns ('Years' column in this example), in a variable (sheet_years). You can do same with other columns.

Rows in the saved column are automatically saved as list items, so we can iterate over these items using our for loop. You can replace it with your own code, instead of just printing the items in the list.

If your excel file contains more than one sheet, you can use the sheet_name parameter of the read_excel() method.

After doing the job with pandas, you can then send the output to your selenium code to fill the forms.

More information here:

Upvotes: 1

Related Questions