-1

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

2
  • I couldn't find that the xpath you are looking for at all. Besides, you are calling 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 the click function; you have to pass one of the elements of the list. And rather than use calls to sleep, better would be to call driver.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. Commented Oct 4, 2020 at 11:48
  • Does this answer your question? AttributeError: 'list' object has no attribute 'click' - Selenium Webdriver Commented Oct 4, 2020 at 14:13

1 Answer 1

0

See my comment to your posted question. I did in the end find your button, but it is not clickable without resorting to using JavaScript:

from selenium import webdriver

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
try:
    driver.implicitly_wait(6) # wait up to 6 seconds to find an element
    driver.get("https://www.nike.com/ch/fr/launch?s=upcoming")
    
    loginBtns = driver.find_elements_by_xpath("/html/body/div[2]/div/div/div[1]/div/header/div[1]/section/div/ul/li[1]/button")
    if loginBtns:
        #loginBtns[0].click()
        driver.execute_script('arguments[0].click()', loginBtns[0])
    else:
        print('Could not find login button.')
finally:
    driver.quit()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.