0

This a program of Data driven testing, where email id and password is taking from Excel sheet. But I am not to able get the data from excel sheet getting an error. I have already attached the screenshot.

Code trial:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import openpyxl
import XLUtilities
import time

driver=webdriver.Chrome(executable_path="C:/Users/sonu.j.kumar/Downloads/chromedriver_win32/chromedriver.exe")
driver.maximize_window()
driver.get("https://www.flipkart.com/account/login?ret=/")
driver.implicitly_wait(5)
path="C://Users/sonu.j.kumar/PycharmProjects/Login_Credentials.xlsx"

wb=openpyxl.load_workbook(path)
sheet=wb["Sheet1"]

user_name=(sheet['A2'].value)
print(user_name)
pwd=(sheet['B2'].value)
print(pwd)

driver.find_elements_by_xpath("//input[@autocomplete='off'][@class='_2zrpKA _1dBPDZ']").send_keys(user_name)
driver.find_elements_by_class_name("_2zrpKA _3v41xv _1dBPDZ").send_keys(pwd)
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    I got the solution, I just removed th "s" from elements in " find_element_by_xpath" and it starts working. – Sonu Kumar Aug 07 '20 at 09:28

1 Answers1

0

This error message...

AttributeError: 'list' object has no attribute 'send_keys'

...implies that your program have attempted to invoke send_keys() method on a List element.


send_keys(*value)

send_keys(*value) simulates typing into the element.

So send_keys() is a WebElement method and can't be invoked on a List.


Solution

Instead of find_elements_by_xpath() and find_elements_by_class_name() you need to use find_element_by_xpath() and find_element_by_class_name(). Effectively your line of code will be:

driver.find_element_by_xpath("//input[@autocomplete='off'][@class='_2zrpKA _1dBPDZ']").send_keys(user_name)
driver.find_element_by_class_name("_2zrpKA _3v41xv _1dBPDZ").send_keys(pwd)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352