Geckodriver error: "FirefoxWebElement has no len()"

Geckodriver error: "FirefoxWebElement has no len()"

我安装了 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: object of type 'FirefoxWebElement' has no len()"

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

您需要 .find_elements_by_tag_name()...复数形式(注意 "elements" 中的 "s")。您使用的单数版本只会 return 一个元素并且没有长度 (len).