0

I'm new in Python and I'm trying to use Selenium in Debian but it doesn't work, more concretely it seems to stay in a loop and nothing happens. The next script is the test that I've used:

#!/usr/bin/env python from selenium import webdriver browser = webdriver.Firefox() browser.get('http://www.python.org') 

When I interrupt the script the following text appears:

Traceback (most recent call last):

File "prueba_parseo.py", line 7, in browser = webdriver.Firefox() File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 154, in init keep_alive=True)

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 140, in init self.start_session(desired_capabilities, browser_profile)

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 229, in start_session response = self.execute(Command.NEW_SESSION, parameters)

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 295, in execute response = self.command_executor.execute(driver_command, params)

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 464, in execute return self._request(command_info[0], url, body=data)

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 488, in _request resp = self._conn.getresponse()

File "/usr/lib/python2.7/httplib.py", line 1111, in getresponse response.begin()

File "/usr/lib/python2.7/httplib.py", line 444, in begin version, status, reason = self._read_status()

File "/usr/lib/python2.7/httplib.py", line 400, in _read_status line = self.fp.readline(_MAXLINE + 1)

File "/usr/lib/python2.7/socket.py", line 476, in readline data = self._sock.recv(self._rbufsize)

KeyboardInterrupt

I've been searching for an answer, but nothing works. I've changed the versions of the packages, export no_proxy="localhost,127.0.0.1"

OS: Debian 5

Python: 2.7

Selenium: 3.5

Geckodriver: 0.17.0

Firefox: 52.0

I don't know what else to do or what to change. Thank you very much!

3
  • Please confirm your Firefox 52 are compatible with Geckodriver 0.17.0 and Selenium 3.5, I use chrome in most time in case you want to try on chrome, my chrome is 60, chromedriver is 2.30, selenium 3.4.0. I think selenium 3.5.0 should be ok.
    – yong
    CommentedSep 20, 2017 at 10:18
  • Yes, they are compatible. Maybe I should change the browser and try with chrome.
    – user8639814
    CommentedSep 20, 2017 at 11:53
  • I've found the answer. The problem was that I was launching the script remotely and not from the local computer.
    – user8639814
    CommentedSep 20, 2017 at 15:08

1 Answer 1

1

My guess is that it actually all goes well and the browser is started in background. The reason why it's staying open is probably because of the default option keep_alive=True I can see in your traceback.

Try closing the browser using browser.close() or browser.quit() when you are done with the tests.

From the documentation:

Finally, the browser window is closed. You can also call quit method instead of close. The quit will exit entire browser whereas close` will close one tab, but if just one tab was open, by default most browser will exit entirely.

http://selenium-python.readthedocs.io/getting-started.html#simple-usage

2
  • Still staying in the loop, nothing changes and the same text appears. It looks like the problem comes from webdriver but I don't know why.
    – user8639814
    CommentedSep 20, 2017 at 9:21
  • "keep_alive=True" is not the reasonCommentedDec 20, 2017 at 16:05