Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23305

How can I read an Excel file using Python Selenium and insert it into my webform?

$
0
0

I created a script to insert data from an Excel file into my web form via Selenium Python but I keep getting an error.I've tried several options but this is the only one that works best at the momentThis is the current error message:

KloecknerTraceback (most recent call last):File "C:\Users\user\Desktop\automate_csv - Copy.py", line 23, in for line in openpyxl.active:AttributeError: module 'openpyxl' has no attribute 'active'

#-------------------------------------------------------------------------------# Importsfrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom webdriver_manager.chrome import ChromeDriverManagerimport openpyxlimport time#-------------------------------------------------------------------------------# Setupwb = openpyxl.load_workbook('data13.xlsx')sheet = wb.activefor rowno in range(2, sheet.max_row+1):    url = sheet.cell(row=rowno, column=2).value    print(url)    userid = sheet.cell(row=rowno, column=3).value    pw = sheet.cell(row=rowno, column=4).value#-------------------------------------------------------------------------------# Web Automation    for line in openpyxl.active:        driver = webdriver.Chrome()        driver.get('https://mysite.domain/?page_id=311')        Add_to = driver.find_element(By.XPATH, "//*[@id='site-content']/div/div/article/ul/li[9]/a[2]")        Add_to_cart.click()        time.sleep(3)        driver.get('https://mysite.domain/?page_id=385')        name_field = driver.find_element(By.XPATH, "//*[@id='first_name']")        name_field.send_keys(line[0])        age_field = driver.find_element(By.XPATH, "//*[@id='last_name']")        age_field.send_keys(line[1])        Adress = driver.find_element(By.XPATH, "//*[@id='address_1']")        Adress.send_keys(line[2])        Zip = driver.find_element(By.XPATH, "//*[@id='postcode']")        Zip.send_keys(line[3])        City = driver.find_element(By.XPATH, "//*[@id='city']")        City.send_keys(line[4])        Phone = driver.find_element(By.XPATH, "//*[@id='phone']")        Phone.send_keys(line[5])        Email = driver.find_element(By.XPATH, "//*[@id='email']")        Email.send_keys(line[6])        time.sleep(3)        Submit = driver.find_element(By.XPATH, "//*[@id='submit']")        Submit.click()        time.sleep(1)#-------------------------------------------------------------------------------

I can't figure out what I'm doing wrong.


Viewing all articles
Browse latest Browse all 23305

Trending Articles



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