I'm trying to write a login script for phones that takes the URL, user, and password from a CSV file and then inputs it to my function. I would love for it to loop so once it completes the first login it uses the next row in the CSV file to update the variables until it has reached the end of the CSV file.
My CSV table file looks like this:
url,user,pass
10.10.10.1,bob,notclean
10.10.10.2,sara,weeee
10.10.10.3,jim,elmo
This is my code thus far. If I replace those variables in the function with the details from CSV file it works.
import selenium
import time
from pandas import DataFrame, read_csv
import pandas as pd
import numpy as np
#open csv file and read table
file = r'table.csv'
df = pd.read_csv(file)
#login function
def login_user(site, login, upass):
driver = webdriver.Chrome(executable_path="chromedriver.exe")
driver.get(site)
time.sleep(6)
driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/form/div/div[1]/label/div/div[2]/div/input').send_keys(login)
driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/form/div/div[2]/label/div/div[2]/div/input').send_keys(upass)
driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/form/div/div[3]/div/div').click()
How do I correlate url to site, user to login, and upass to pass in the excel document and then loop the function to retry my logins until I've reached the end of the CSV file?