1

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

Claudiu
  • 224,032
  • 165
  • 485
  • 680
  • what happens if you lose the `implicitly_wait(5)`? – root Jan 11 '13 at 16:46
  • @root: the same, it still freezes. I only tried the implicitly_wait because it was freezing in the first place. It also freezes without using the `waiter` – Claudiu Jan 11 '13 at 16:47
  • When I do exactly this, it works fine, and I get a timeout exception. What is freezing here? Starting up Firefox? The waiter? – Silas Ray Jan 11 '13 at 16:51
  • @sr2222: the `ff.find_element_by_name("foo")` freezes, whether I use a waiter or not. What version of firefox/selenium are you using? – Claudiu Jan 11 '13 at 17:12
  • Version issue between Firefox and selenium. Almost every release of Firefox over the last year or so has broken selenium element lookup or something else. – Silas Ray Jan 11 '13 at 17:15

3 Answers3

1

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

Community
  • 1
  • 1
Amey
  • 8,470
  • 9
  • 44
  • 63
1

It seems to be a bug in version 2.26.0, pip install selenium==2.27.0 fixed it on my computer.

root
  • 76,608
  • 25
  • 108
  • 120
0

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.

Claudiu
  • 224,032
  • 165
  • 485
  • 680