How to handle Selenium WebDriver Error: AttributeError: 'list' object has no attribute 'click'?
Last Updated :
23 Jul, 2025
When working with Selenium WebDriver to automate web interactions, it's common to encounter errors if the code isn't structured correctly. One such common issue is the AttributeError: 'list' object has no attribute 'click'. This error occurs in Python Selenium scripts when you attempt to use the click()
method on a list of web elements instead of an individual element. In this article, we’ll explain why this error happens and provide a simple solution to fix it, helping you handle Selenium WebDriver errors more effectively
Selenium is used for web automation. When automating web interactions with Selenium WebDriver, it’s common to encounter errors due to incorrect usage of methods. One such error is:
AttributeError: 'list' object has no attribute 'click'
This error occurs when we mistakenly attempt to use the click() method on a list of elements, which doesn’t support this action. acting on the list rather than the actual element causes this error. In this article, we’ll walk through a simple Selenium script that will show how this error can be generated and then we will see how to correct it.
Example:
Let's see this through the example, In this example we simply will grab all the anchor tags on the GeeksForGeeks official website. Below is a selenium script using Python that attempts to find all <a> tags on a webpage and click on them.
Python
# Description: This is a simple script to get the number of anchor tags in a webpage
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
# create webdriver object
driver = webdriver.Chrome()
# get geeksforgeeks.org
driver.get('https://www.geeksforgeeks.org/');
# Sleep for 5 seconds
time.sleep(5)
# get search box
ancTags = driver.find_elements(By.TAG_NAME, 'a')
# print number of anchor tags
print(f"No of Anchors: {len(ancTags)}")
# click on the first anchor tag
ancTags.click() # This will throw an error as click() is not a method of list
# sleep for 5 seconds
time.sleep(5)
# close the browser
driver.quit()
Output:
Output of Incorrect codeAs we can see, it generates an error because of the incorrect usage of the click() method. The method find_elements(By.TAG_NAME, 'a') returns a list of WebElements (all anchor tags on the page in this case). However, the click() method is only available for individual WebElement objects, not for a list of elements.
When we try to use click() on atrTags, which is a list, the program raises an AttributeError because lists do not have the click() method.
Now let's fix this code, to fix this code we need either
- click on specific element from the list of anchor tags.
- iterate over list and click on each element individually
I want to apply click on the first element only, so in this case my fixed code will be
Python
# Description: This is a simple script to get the number of anchor tags in a webpage
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
# create webdriver object
driver = webdriver.Chrome()
# get geeksforgeeks.org
driver.get('https://www.geeksforgeeks.org/');
# Sleep for 5 seconds
time.sleep(5)
# get search box
ancTags = driver.find_elements(By.TAG_NAME, 'a')
# print number of anchor tags
print(f"No of Anchors: {len(ancTags)}")
# click on first anchor tag
ancTags[0].click() # corrected code
# sleep for 5 seconds
time.sleep(5)
# close the browser
driver.quit()
Output of Correct CodeThis corrected python script will print the number of anchor tags found on the page and attempt to click on first one.
Output:
Conclusion
The AttributeError: 'list' object has no attribute 'click' occurs when trying to call the click()
method on a list of web elements instead of a single WebElement. To resolve this, you should either click on a specific element from the list or iterate through the list and click on each element individually.
By understanding how Selenium’s find_elements() method works and implementing the correct solution, you can prevent such errors and improve your automation scripts.
Similar Reads
Software Testing Tutorial Software testing is an important part of the software development lifecycle that involves verifying and validating whether a software application works as expected. It ensures reliable, correct, secure, and high-performing software across web, mobile applications, cloud, and CI/CD pipelines in DevOp
10 min read
What is Software Testing? Software testing is an important process in the Software Development Lifecycle(SDLC). It involves verifying and validating that a Software Application is free of bugs, meets the technical requirements set by its Design and Development, and satisfies user requirements efficiently and effectively.Here
11 min read
Principles of Software testing - Software Testing Software testing is an important aspect of software development, ensuring that applications function correctly and meet user expectations. From test planning to execution, analysis and understanding these principles help testers in creating a more structured and focused approach to software testing,
3 min read
Software Development Life Cycle (SDLC) Software Development Life Cycle (SDLC) is a structured process that is used to design, develop, and test high-quality software. SDLC, or software development life cycle, is a methodology that defines the entire procedure of software development step-by-step. The goal of the SDLC life cycle model is
8 min read
Software Testing Life Cycle (STLC) The Software Testing Life Cycle (STLC) is a process that verifies whether the Software Quality meets the expectations or not. STLC is an important process that provides a simple approach to testing through the step-by-step process, which we are discussing here. Software Testing Life Cycle (STLC) is
7 min read
Types of Software Testing Software testing is a important aspect of software development life-cycle that ensures a product works correctly, meets user expectations, and is free of bugs. There are different types of software testing, each designed to validate specific aspects of an application, such as functionality, performa
15+ min read
Levels of Software Testing Software Testing is an important part of the Software Development Life Cycle which is help to verify the product is working as expected or not. In SDLC, we used different levels of testing to find bugs and errors. Here we are learning those Levels of Testing in detail.Table of ContentWhat Are the Le
4 min read
Test Maturity Model - Software Testing The Test Maturity Model (TMM) in software testing is a framework for assessing the software testing process to improve it. It is based on the Capability Maturity Model(CMM). It was first produced by the Illinois Institute of Technology to assess the maturity of the test processes and to provide targ
8 min read
SDLC MODELS
TYPES OF TESTING