as you can see I'm starting coding a bot to cop sneakers on SNKRS. I've already coded a few useless things but we don't care. I want the bot to click on the log in button, but at the end when I run the code, it opens Chrome then it opens the nike website but then it doesn't click on the button and I have this error message:
Traceback (most recent call last):
File "C:/Users/xxx/xxx/xxx/xxx/xxx/SNKRS_bot/snkrs bot.py", line 11, in <module>
loginBtn = driver.find_elements_by_xpath("/html/body/div[2]/div/div/div[1]/div/header/div[1]/section/div/ul/li[1]/button").click()
AttributeError: 'list' object has no attribute 'click'
Here is my code :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.nike.com/ch/fr/launch?s=upcoming")
time.sleep(3)
loginBtn = driver.find_elements_by_xpath("/html/body/div[2]/div/div/div[1]/div/header/div[1]/section/div/ul/li[1]/button").click()
time.sleep(6)
driver.quit()
Thanks a lot
find_elements_by_xpath, which returns a list. Assuming it finds one or more elements that satisfies the xpath, you can't pass a list to theclickfunction; you have to pass one of the elements of the list. And rather than use calls tosleep, better would be to calldriver.implcitly_wait(6)at the very beginning. The driver will then wait to up to 6 seconds to find an element but will return much sooner if it finds the element sooner.