close

[Solved] TypeError: ‘WebElement’ object is not iterable error

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TypeError: ‘WebElement’ object is not iterable error in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How TypeError: ‘WebElement’ object is not iterable error Error Occurs?

Today I get the following error TypeError: ‘WebElement’ object is not iterable error in python.

How To Solve TypeError: ‘WebElement’ object is not iterable error Error ?

  1. How To Solve TypeError: 'WebElement' object is not iterable error Error ?

    To Solve TypeError: 'WebElement' object is not iterable error Error The problem is that you are using find_element_by_xpath which return only one WebElement (which is not iterable), the find_elements_by_xpath return a list of WebElements.

  2. TypeError: 'WebElement' object is not iterable error

    To Solve TypeError: 'WebElement' object is not iterable error Error The problem is that you are using find_element_by_xpath which return only one WebElement (which is not iterable), the find_elements_by_xpath return a list of WebElements.

Solution 1

The problem is that you are using find_element_by_xpath which return only one WebElement (which is not iterable), the find_elements_by_xpath return a list of WebElements.

Solution: replace find_element_by_xpath with find_elements_by_xpath

Solution 2

Below code worked for me.

from selenium import webdriver
driver=webdriver.Firefox()
driver.get("https://www.google.co.in/")
list_links=driver.find_elements_by_tag_name('a')

for i in list_links:
    print i.get_attribute('href')

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read