【Python】处理 TypeError: ‘FirefoxWebElement‘ object is not iterable
生活随笔
收集整理的這篇文章主要介紹了
【Python】处理 TypeError: ‘FirefoxWebElement‘ object is not iterable
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
編寫下面的代碼:
from selenium import webdriverdriver = webdriver.Firefox() driver.maximize_window() driver.implicitly_wait(50) driver.get("http://www.baidu.com") tag_names = driver.find_element_by_tag_name('input') for tag_name in tag_names:print(tag_name) print(type(tag_names)) driver.quit()運行時報錯:
TypeError: ‘FirefoxWebElement’ object is not iterable
錯誤原因是:錯誤地使用了API,實際上應(yīng)該是find_elements_by_tag_name
沒加s的話只是定位了單個元素,而加上s可以定義多個元素,才能返回可迭代的list對象!
運行結(jié)果示意:
總結(jié)
以上是生活随笔為你收集整理的【Python】处理 TypeError: ‘FirefoxWebElement‘ object is not iterable的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【操作系统】进程与程序的比较
- 下一篇: 【Java】获取并打印当前堆栈的方法