Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97762

How do I pass information from CSV into my Selenium(Python) automation program?

$
0
0

everyone. I am automating the process of creating blackout dates using selenium. Thus far, I am able to successfully create one blackout date with the script that I have written. What I need to do is be able to pass information I get from a CSV (which are different dates and times) into the program so I don't have to manually run the script 90 plus times to get all of the blackout dates created. My code is as follows(I have all the necessary imports and everything works):

"""Creating blackout date w/ settings"""

dateElem = 
browser.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div[2]/div/div/div/div/ng-include/div/form/fieldset/div[6]/div[1]/div[2]/input')
browser.execute_script("arguments[0].removeAttribute('readonly')", dateElem);
dateElem.clear()
dateElem.send_keys("07/14/2020")

inputElement_HH = browser.find_element_by_id("scanBlackoutHour")
inputElement_HH.send_keys("08")

inputElement_MM = browser.find_element_by_id("scanBlackoutMinute")
inputElement_MM.send_keys("37")

am_or_pm = Select(browser.find_element_by_id("scanBlackoutTimeFrame"))
am_or_pm.select_by_index(1)

durationElem = browser.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div[2]/div/div/div/div/ng-include/div/form/fieldset/div[12]/div[6]/input')
durationElem.send_keys('12')

saveElem = browser.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div[2]/div/div/div/div/ng-include/div/form/fieldset/div[17]/div[2]/button')
saveElem.click()
savescanElem = browser.find_element_by_id("btnScanConfigSave").click()

The CSV file I am using returns the following information in this format:

['\ufeffDate', 'StartTime (Hour)', 'StartTime (Minute)', 'Timeframe', 'Blackout Duration']
['10/17/2020', '10', '9', 'PM', '10']
['10/20/2021', '11', '5', 'AM', '8']
...

If you look at the code, you'll see dateElem, inputElementHH, inputElementMM, am_or_pm and durationElem with send_keys and then the date, the hour, the minute, 1 for PM, duration time. How can I pass the data from the list generated by the CSV into those send_keys places for the variables I mentioned? What it should look like after a successful passthrough is this:

"""Creating blackout date w/ settings"""

dateElem = 
browser.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div[2]/div/div/div/div/ng-include/div/form/fieldset/div[6]/div[1]/div[2]/input')
browser.execute_script("arguments[0].removeAttribute('readonly')", dateElem);
dateElem.clear()
dateElem.send_keys("10/17/2020")

inputElement_HH = browser.find_element_by_id("scanBlackoutHour")
inputElement_HH.send_keys("10")

inputElement_MM = browser.find_element_by_id("scanBlackoutMinute")
inputElement_MM.send_keys("9")

am_or_pm = Select(browser.find_element_by_id("scanBlackoutTimeFrame"))
am_or_pm.select_by_index(1)

durationElem = browser.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div[2]/div/div/div/div/ng-include/div/form/fieldset/div[12]/div[6]/input')
durationElem.send_keys('10')

saveElem = browser.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div[2]/div/div/div/div/ng-include/div/form/fieldset/div[17]/div[2]/button')
saveElem.click()
savescanElem = browser.find_element_by_id("btnScanConfigSave").click()

As an additional note, Select_by_index is to be an integer with 0 being AM and 1 being PM so for that value I need an integer passed through, not a string. Again, I want this program to pass through all the info from each list generated by the CSV into the correct place on separate run throughs. Any help is appreciated. Thank you in advance.


Viewing all articles
Browse latest Browse all 97762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>