Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geckodriver error: "FirefoxWebElement has no len()"

I installed geckodriver since selenium is no longer compatible with recent versions of Firefox. Please note that I am using Spyder on a Mac. Before, I had successfully scraped data from a website, but once I switched to geckodriver, I had to make modifications to the script. For example,

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

is now

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

I modified the following:

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

to:

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

but I get the following error: "TypeError: object of type 'FirefoxWebElement' has no len()"

I am trying to get the count of the list on the following website and so I can loop through the list under "*Il adi": https://sonuc.ysk.gov.tr/module/sspsHalkoylamasiYeni.jsf

like image 876
bayrah Avatar asked Feb 05 '23 13:02

bayrah


1 Answers

You want .find_elements_by_tag_name()... the plural version (notice the "s" in "elements"). The singular version you are using will only return one element and does not have a length (len).

like image 113
JeffC Avatar answered Feb 16 '23 03:02

JeffC