15

I've just installed Selenium for the first time, and I'm having trouble to get started.

Installation went fine with pip:

pip install selenium

And I can import selenium within Python.

Now I'm trying to run the following sample script:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title

What happens is that Firefox opens, but it does not navigate to "http://www.python.org" (similar to the behaviour described in this question - it only shows a blank page)

For about 60 seconds nothing happens, until the following exception raised:

Traceback (most recent call last):
  File "selenium-test.py", line 4, in <module>
    driver = webdriver.Firefox()
  File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 61, in __init__
    desired_capabilities=capabilities)
  File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 72, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 114, in start_session
    'desiredCapabilities': desired_capabilities,
  File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 165, in execute
    self.error_handler.check_response(response)
  File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 136, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: u'<HTML><HEAD>\r\n<TITLE>Network Error</TITLE>\r\n</HEAD>\r\n<BODY>\r\n<FONT face="Helvetica">\r\n<big><strong></strong></big><BR>\r\n</FONT>\r\n<blockquote>\r\n<TABLE border=0 cellPadding=1 width="80%">\r\n<TR><TD>\r\n<FONT face="Helvetica">\r\n<big>Network Error (tcp_error)</big>\r\n<BR>\r\n<BR>\r\n</FONT>\r\n</TD></TR>\r\n<TR><TD>\r\n<FONT face="Helvetica">\r\nA communication error occurred: "Operation timed out"\r\n</FONT>\r\n</TD></TR>\r\n<TR><TD>\r\n<FONT face="Helvetica">\r\nThe Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.\r\n</FONT>\r\n</TD></TR>\r\n<TR><TD>\r\n<FONT face="Helvetica" SIZE=2>\r\n<BR>\r\nFor assistance, contact your network support team.\r\n</FONT>\r\n</TD></TR>\r\n</TABLE>\r\n</blockquote>\r\n</FONT>\r\n</BODY></HTML>'

These are the software versions

  • Firefox ESR 17.0.5
  • Selenium (Python bindings) 2.35.0
  • Python 2.6.6
  • Red Had Linux 6.3
  • the "Firefox WebDriver 2.35.0" browser extension is installed
Community
  • 1
  • 1
E.Z.
  • 6,393
  • 11
  • 42
  • 69
  • run a local webserver and then try and get http://localhost. There might be proxy configuration issues depending on your network setup. – Marwan Alsabbagh Sep 12 '13 at 17:41
  • what happens when you just start firefox normally and visit python.org does that work. – Marwan Alsabbagh Sep 12 '13 at 17:42
  • I have faced the same problem, but the Selenium was already in the newest version, so was Firefox and setting network proxy didn't help. I came across note on Selenium issues page on github: `FIREFOX 48+ IS ONLY COMPATIBLE WITH GECKODRIVER. Any issue logged here for 48+ will be closed as a duplicate of #2559` And I have downgraded my Firefox from 49 to 45. It works well. I assume that this `Geckodriver` is the solution from now on. – mpiskore Sep 22 '16 at 21:22

4 Answers4

5

Ok, after searching around for a while I noticed that usually the problem was a bug in Selenium (possible, but rather unlikely), or a proxy issue. Still, none of the answers suggesting how to solve the proxy issue seemed to work.

Finally I got it: you need to unset all proxy settings everywhere (environment variables, and - in my case this was the issue- on Gnome). Later when you create the webdriver, you need to pass a profile which sets the browser proxy settings to what you actually use (in my case an automatic config url)

1) Unset the http_proxy environment variable (which is used by urllib)

export http_proxy=

2) Cleared Gnome proxy settings: System --> Preferences --> Network Proxy --> Select "Direct Internet Connection"

3) Started webdriver.Firefox() with a profile which configures the proxy (in this case it's an automatic proxy configuration)

fp = webdriver.FirefoxProfile()
# Here "2" stands for "Automatic Proxy Configuration"
fp.set_preference("network.proxy.type", 2)
fp.set_preference("network.proxy.autoconfig_url",
                  "http://proxy-address-here:8080/") 
driver = webdriver.Firefox(firefox_profile=fp)
E.Z.
  • 6,393
  • 11
  • 42
  • 69
  • What about webdriver.Proxy class? Seems you can set it to "" blank. You are using the long way by selecting and setting a profile proxy. Correct me if im wrong. Following your example i see that the python WebDriver is better than the unnoficial PHP versions by far. Worked out of the box. – m3nda Jun 02 '15 at 14:32
  • If you're using Selenium 4.0.0, then point 1) is important, even if you have set no_proxy=localhost - see https://github.com/SeleniumHQ/selenium/issues/9925 – Cito Oct 20 '21 at 15:12
2

Needs to upgrade the selenium, If you are using Latest version of Firefox, you should use latest version of selenium

For Python, Enter this command

pip install -U selenium

For Java, Remove the old jar and Download Latest Version from here http://www.seleniumhq.org/download/ and Attach into build path. It will work find . Happy Testing with Firefox

0

Please also try turning off your localhost(127.0.0.1) web server if you have any running on the usual port 80.

The Firefox Binary does not allow you to load the profile if there is a localhost server running.

See line 81 in selenium\webdriver\firefox\firefox_binary.py which points to the function / method is_connectable(self)

def is_connectable(self):

    """Trys to connect to the extension but do not retrieve context."""
    try:
        socket_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        socket_.settimeout(1)
        socket_.connect(("127.0.0.1", self.profile.port))
        socket_.close()
        return True
    except socket.error:
        return False

GLHF

-1

I had the same issue i referred the link to check the version of gecko driver : https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html

Download the version accordingly which fixed the issue

Akshay
  • 1
  • Pointing out where to download different versions isn't super helpful, especially being an older question, it may work as expected with new versions. – Ben Jun 11 '20 at 22:35