user8639814
user8639814

Reputation:

Selenium doesn't open the browser in Python

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!

Upvotes: 0

Views: 4059

Answers (1)

Hugo G
Hugo G

Reputation: 16484

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

Upvotes: 1

Related Questions