Have been trying to emulate examples posted earlier, yet got stuck.
I have a simple web form: Last name, name, email, password, confirm password.
Also a .csv with 4 columns that corresponds to the form
Last name Name Email Password 0 Brown Stan brown@stan.com 12345678 1 White Eagle white@eagle.com 123456789 2 Dante Aligr adant@mail.au 98765432
So, all I want is to feed the 3 entries to the form and click “Sent” after each entry.
I copycated a code from here that seemed passing but I keep getting this
File "C:Usersuntitled2.py", line 43, in <module> last.send_keys(lname) AttributeError: 'list' object has no attribute 'send_keys'
the code I tried
from selenium import webdriver from selenium.webdriver.firefox.options import Options from selenium.webdriver.firefox.firefox_binary import FirefoxBinary options = Options() options.binary_location = FirefoxBinary(r"C:Program FilesMozilla Firefoxfirefox.exe") driver = webdriver.Firefox(executable_path=r'C:WebDriverbingeckodriver.exe', firefox_options=options) import time import pandas as pd reg = pd.read_csv('Form.csv', header=0, delimiter=';', sep=r's*;s*') print(reg) lname = reg['Last name'].tolist() name = reg['Name'].tolist() mail = reg['Email'].tolist() password = reg['Password'].tolist() password_c = reg['Password'].tolist() driver.get('url') first = driver.find_elements_by_xpath("/html/body/div/div[3]/form/div[2]/div/div[2]/div[2]/div/div/div[2]/div/div[1]/div/div[1]/input") last = driver.find_elements_by_xpath("/html/body/div/div[3]/form/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input") mail = driver.find_elements_by_xpath("/html/body/div/div[3]/form/div[2]/div/div[2]/div[3]/div/div/div[2]/div/div[1]/div/div[1]/input") password = driver.find_elements_by_xpath("/html/body/div/div[3]/form/div[2]/div/div[2]/div[4]/div/div/div[2]/div/div[1]/div/div[1]/input") password_confirm = driver.find_elements_by_xpath("/html/body/div/div[3]/form/div[2]/div/div[2]/div[4]/div/div/div[2]/div/div[1]/div/div[1]/input") submit = driver.find_elements_by_xpath('/html/body/div/div[3]/form/div[2]/div/div[3]/div[1]/div/div/span/span') for lname, name, mail, password, password_c in zip(lname, name, mail, password, password_c): last.send_keys(lname) time.sleep(1) first.send_keys(name) time.sleep(1) mail.send_keys(mail) time.sleep(1) password.send_keys(password) time.sleep(1) password_confirm.send_keys(password_c) time.sleep(1) submit.click() time.sleep(3)
Any nudge into the right direction will be highly appreciated since I have seen plenty of examples of using lists with send_keys()
Thanks!
Advertisement
Answer
The error message indicates that you are using send_keys()
with plain python list
s.
According to Selenium docs, find_elements_by_xpath
does indeed return a list.
It’s possible that you meant to use find_element_by_xpath
(without the ‘s’ after element)?