0

I am trying to click a button with the .click method, but if I type .cl, my IDE doesn’t even suggest the .click function. The Chrome window opens but then after that, Python throws an error. I added two pictures - in the first, you can see my code, and in the second, you can see the error that is thrown:

the two windows

3
  • find_elements_by_xpath will return a list. You'll want to run click on an element in the list returned by that method Commented Mar 13, 2021 at 17:16
  • it's important to note that Python is not case-insensitive; the function should be click() not Click() Commented Mar 13, 2021 at 17:21
  • Welcome to Stack Overflow! Please avoid posting images (or worse, links to images) of code or errors. Anything text-based (code and errors) should be posted as text directly in the question itself and formatted properly. You can get more formatting help here. You can also read about why you shouldn't post images/links of code. Commented Mar 14, 2021 at 13:04

1 Answer 1

1

As you can see from the error, Python tries to access the Click attribute for a list object. This is happening because the .find_elements_by_xpath() method returns a list.

Therefore, the solution for your problem would be to pull an item from that list and use the click method on it, rather than on the list itself.

sb[0].click()
Sign up to request clarification or add additional context in comments.

2 Comments

if there's only element could use find_element_by_xpath() instead of find_elements_by_xpath()
True, although OP didn't specify a guarantee that it will return only 1 element.

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.