Reputation: 229591
I'm using selenium with Python and it always freezes when I search for an element that does not exist. I've really tried everything (Firefox version 17.0.1):
>>> import selenium
>>> selenium.__version__
'2.26.0'
>>> from selenium import webdriver
>>> from selenium.webdriver.support.ui import WebDriverWait
>>> ff = webdriver.Firefox()
>>> ff.implicitly_wait(5)
>>> ff.set_page_load_timeout(5)
>>> ff.set_script_timeout(5)
>>> waiter = WebDriverWait(ff, 5)
>>> waiter.until(lambda ff: ff.find_element_by_name("foo"))
That last command freezes indefinitely. How do I get firefox to simply return None or throw an exception when it doesn't find an element, instead of hanging forever? I'm using selenium 2.26.0
Upvotes: 1
Views: 1251
Reputation: 80456
It seems to be a bug in version 2.26.0, pip install selenium==2.27.0
fixed it on my computer.
Upvotes: 1
Reputation: 8548
Based on answer found here
If you are using Firefox 17 and Selenium 2.26.0 then you are hitting defect #4814: http://code.google.com/p/selenium/issues/detail?id=4814
Upvotes: 1
Reputation: 229591
For now, I'm using this work-around:
def selenium_safe_find_element_by_name(ff, element_name):
elements = ff.find_elements_by_name(element_name)
if not elements:
raise ValueError("<name=%s> not found" % (element_name,))
return elements[0]
But it really seems that this should somehow work without that workaround.
Upvotes: 0