Use DaTa FraMe vaLues to fill HTML fOrMS via Selenium
This article is the next phase of my previous article. How to create users. In this phase, we will upload the data from a.csv file to the HTML forms.

Let’s start...

1- Upload CSV file

2- Create Data Frame

2- Use Selenium to fill HTML forms with data frame values

from selenium.webdriver.support.select import Select

import pandas as pd



try:

# Read CSV File

client_df = pd.read_csv('D:/.../generate_user_data.csv')

name = client_df.iloc[:, 0]



# Create Users

driver.implicitly_wait(30)

driver.get('your link')



# for loop

size = len(client_df.index)

for a in range(size):

driver.implicitly_wait(10) # Create new column with . between names client_df.iloc[:,0] = name.replace(' ', '.', regex=True) # Enter User Name from the Dataframe driver.find_element_by_xpath("// input[ @ id = 'Username']").send_keys(str(client_df.iloc[:,0].values[a]))



# Enter Email

driver.find_element_by_id('Email').send_keys(str(client_df.iloc[:,1].values[a]))



# Enter Password

client_df['password'] = "pwd"

driver.find_element_by_xpath("// input[ @ id = 'Password']").send_keys("pwd")

driver.find_element_by_id ('ConfirmPassword').send_keys("pwd")



# Select the Role

level = Select(driver.find_element_by_id('RoleName'))

level.select_by_visible_text('Admin')

driver.implicitly_wait(10)



driver.execute_script ("window.scrollTo(0,document.body.scrollHeight)")



# Click Create

driver.implicitly_wait (10)

driver.find_element_by_class_name('card-footer').submit()



# Go to the link again

driver.get ('your link')





finally:

driver.quit ()

In this code, I am creating user credentials.

Create new column with . between names

This means my application do not accepts white spaces. So i have added a dot. Enter User Name from the Dataframe

This means the data frame i have created with the .csv file, its values are fetched here in the web HTML form using selenium. You must have noticed that i am converting the value into string. As the textfield input is string so that's why am using str().

client_df.iloc[:,1] you can easily understand this thorugh my story i wrote about

This means the data frame i have created with the .csv file, its values are fetched here in the web HTML form using selenium. You must have noticed that i am converting the value into string. As the textfield input is string so that's why am using str().client_df.iloc[:,1] you can easily understand this thorugh my story i wrote about Pandas Data fRAME Cheat Sheet — select specific CoLumn and RoW

I believe the rest of the code is self-explanatory. if you have read my previous stories. You must know why I have not added the code chunk for calling browser, getting URL…..

Stay happy and Safe!
['Anum Sadozaeii']
['Selenium', 'HTML', 'Pandas Dataframe']