-1

I am trying to click the login button on a site, however I proceed to get an error.

I have tried getting the element by xpath, id, text and other ways but none worked for me.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import random

while True:
    time.sleep(4)
    browser = webdriver.Chrome("C:\webdrivers/chromedriver.exe")
    #browser = webdriver.Chrome()
    browser.get("https://www.brickplanet.com/login")

    username = browser.find_elements_by_xpath('//*[@id="username"]')
    #username.clear()
    #username.send_keys('KOMKO190')

    password = browser.find_elements_by_xpath('//*[@id="password"]')
    #password.clear()
    #password.send_keys('this is my password btw!')

    login = browser.find_elements_by_id("submit")
    login.click()

The error I'm getting:

Traceback (most recent call last):
  File "C:\Users\DOMA\Desktop\bp hack.py", line 23, in <module>
    login.click()
AttributeError: 'list' object has no attribute 'click'

Process returned 1 (0x1)        execution time : 13.061 s
Press any key to continue . . .
5
  • Hey, sorry, it's not clicking by XPATH but by ID, sorry for my little mistake! Commented Oct 12, 2019 at 20:17
  • Possible duplicate of AttributeError: 'list' object has no attribute 'click' - Selenium Webdriver Commented Oct 12, 2019 at 21:42
  • 1
    The first thing you should do whenever you get an error that you don't know how to solve is to google the error. It's extremely unlikely that you are the first to get that error message and you will likely find a lot of info on the web where the error and possible solutions are discussed. Commented Oct 12, 2019 at 21:43
  • True, but now I can't find how to continue the program even if I get the error Commented Oct 14, 2019 at 11:07
  • The code you have posted here is not going to get you that error some of the time... it's going to happen every single time you run it. Commented Oct 14, 2019 at 13:33

1 Answer 1

0

You are using find_elements_by_id which returns list of elements, that's why you are getting an error - If you are looking for a single element then use find_element_by_id ("element" instead of "elements"). This will return a single element which is found first in DOM.

Sign up to request clarification or add additional context in comments.

1 Comment

This element only appears sometimes, not all of the time, how would I make it if it doesn't see it it just continues the program?

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.