Geckodriver错误:“FirefoxWebElement没有len()”

时间:2017-04-30 22:31:07

标签: python selenium spyder geckodriver

我安装了geckodriver,因为selenium不再与最新版本的Firefox兼容。请注意我在Mac上使用Spyder。之前,我成功地从网站上删除了数据,但是一旦我切换到geckodriver,我就不得不对脚本进行修改。例如,

 browser.find_by_id('closeMessageButton').click() 

现在是

 browser.find_element_by_id('closeMessageButton').click() 

我修改了以下内容:

prov_count = len(browser.find_by_id("j_id48:j_id49:j_id108:cmbSecimCevresi").first.find_by_tag('option'))-1

到:

prov_count = len(browser.find_element_by_id("j_id48:j_id49:j_id108:cmbSecimCevresi").find_element_by_tag_name('option'))-1

但是我收到以下错误:“TypeError:'FirefoxWebElement'类型的对象没有len()”

我正在尝试获取以下网站上的列表计数,因此我可以遍历“* Il adi”下的列表:https://sonuc.ysk.gov.tr/module/sspsHalkoylamasiYeni.jsf

1 个答案:

答案 0 :(得分:3)

你想要.find_elements_by_tag_name() ...复数版本(注意" s" in"元素")。您使用的单数版本只返回一个元素,并且没有长度(len)。