How to Fix AttributeError: ‘list’ object has no attribute ‘click’

Diagram of How to Fix AttributeError: 'list' object has no attribute 'click'

Diagram

AttributeError: ‘list’ object has no attribute ‘click’ error occurs when you are trying to call the click method on a list object but lists do not have a method named click.

Reproduce the error

from selenium import webdriver

driver = webdriver.Chrome()

# Implicit wait
driver.implicitly_wait(0.5)

# URL launch
driver.get("https://appdividend.com")

# Identify an element
m = driver.find_elements_by_name('search')
m.click()

# Browser quit
driver.quit()

Output

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

How to fix the error?

To fix the error, “ensure you are working with a single web element.” If you intend to work with a single element, use methods like find_element_by_* (without the ‘s’) to return a single web element.

If you use methods that return a list of elements (like find_elements_by_*), you must access individual elements and perform actions on them.

For example, if you want to click the first element from the list:

elements = driver.find_elements_by_xpath("search")

elements[0].click()

You can also check if the list is empty before accessing elements from the list.

elements = driver.find_elements_by_xpath("search")

if elements:
  elements[0].click()

I hope this will fix the error.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.