-3
from selenium import webdriver 
from selenium.webdriver.support.ui import Select 
import time 
import os 
driver = webdriver.Chrome("C:\Users\Mani\Desktop\chromedriver.exe")             
driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select") 
li=driver.find_element_by_xpath('/html[1]/body[1]') 
for i in li: 
    print(i.text) 
driver.close()

for i in li:
    TypeError: 'WebElement' object is not iterable
2
  • find_element_by_xpath --> find_elements_by_xpath. The first returns only the first matching object Commented Jul 25, 2019 at 17:14
  • 2
    Possible duplicate of TypeError: 'WebElement' object is not iterable error Commented Jul 25, 2019 at 17:14

1 Answer 1

0

li=driver.find_element_by_xpath('/html[1]/body[1]') will return a single element and you can't iterate using webelement.

You should use li=driver.find_elements_by_xpath('/html[1]/body[1]//li'), if you want to get a list of elements matching with that xpath.

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

Comments

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.