corazza
corazza

Reputation: 32366

Selenium: _wait_until_connectable pauses indefinitely

I'm trying to use Python with Selenium to script Firefox, with the example given on their website:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
assert "Google" in driver.title
driver.close()

When I run this code, it successfully opens a new Firefox window, but then nothing happens. The browser is responsive, can load other pages, but Selenium simply refuses to cooperate with it for some reason.

When I quit the Python script, this is the output:

^CTraceback (most recent call last):
  File "ha.py", line 5, in <module>
    driver = webdriver.Firefox()
  File "/usr/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 46, in __init__
    self.binary, timeout),
  File "/usr/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 46, in __init__
    self.binary.launch_browser(self.profile)
  File "/usr/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 44, in launch_browser
    self._wait_until_connectable() 
  File "/usr/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 89, in _wait_until_connectable
    time.sleep(1)
KeyboardInterrupt

It would seem that it enters an infinite loop in the function _wait_until_connectable.

What seem to be causing this problem and how can I get Selenium to make Firefox become "connectable"?

I glanced over the firefox_binary.py source code and noticed that it mentions an 'extension' in the comments. Should I install some extension in Firefox that enables interaction?

Upvotes: 4

Views: 1348

Answers (2)

Yi Zeng
Yi Zeng

Reputation: 32865

Don't use Firefox Nightly.

Firefox makes some changes on most of the releases, Selenium needs to catch up after the Firefox upgrading.

Quote from CHANGES:

Selenium 2.32

  • Support for FF20 Native Events

Selenium 2.31

  • Support for FF19 native events

See that? Selenium always need to catch up with new Firefox (native events here for example). Assume your Selenium is the latest 2.33.0, then probably try downgrade your Firefox (Nightly is 25, so downgrade to 21 should work, 20 would definitely work).

If your Selenium is not the latest, upgrade first by

pip install -U selenium

Upvotes: 5

Maciej Gol
Maciej Gol

Reputation: 15854

Make sure your Firefox and Selenium are up to date, and that your Selenium version supports your browser. What you might be experiencing is that Selenium starts up a firefox instance with a particular extension called the Webdriver. That, in turn, opens a specific port your python selenium client is trying to connect to send commands to. This is the way your python selenium client and the browser communicate with each other.

I've had a similar issue when sometimes the firefox extension didn't open port rendering python to be stuck waiting.

You could try to set up a selenium server and connect to it instead of creating a new instance of firefox, or once you ensure it's a regression in either the extension or python bindings try downgrading both the firefox and selenium (don't downgrade only one of them as the extension might be closely tied to the firefox version, and the protocol might have changed at some point)

Upvotes: 0

Related Questions