2

I am trying to use the selenium to deal with some website using JavaScript codes. To begin with,I use simple example as below

from selenium import webdriver

browser = webdriver.Firefox()

browser.get('http://www.yahoo.com')

browser.quit()

While this even does not work. The error msg is shown as below. I think I may missed something in selenium or something else. Could you bring me some light on this?

Traceback (most recent call last):
  File "/home/rnie/webdriver-tutorial-1x.py", line 3, in <module>
    browser = webdriver.Firefox()
  File "/usr/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
    keep_alive=True)
  File "/usr/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "/usr/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

I checked the "geckodriver.log", and it shows following error messages:

1479623778556   geckodriver INFO    Listening on 127.0.0.1:49723
1479623778625   mozprofile::profile INFO    Using profile path /tmp/rust_mozprofile.WMDGNONHQTud
1479623778628   geckodriver::marionette INFO    Starting browser /usr/bin/firefox
1479623778641   geckodriver::marionette INFO    Connecting to Marionette on localhost:35691
No protocol specified
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0
furas
  • 134,197
  • 12
  • 106
  • 148
Robin
  • 201
  • 2
  • 14

3 Answers3

0

Pl check path or if you are on Linux have a look for http://www.linuxquestions.org/questions/linux-server-73/can't-open-display-no-protocol-specified-using-gdm-4175462031/

DD Sharma
  • 43
  • 2
  • 10
0

With Selenium 3.0 release, Firefox Selenium driver has been updated to a new driver called Marionette or "geckodriver". This is a separate binary on your system.

See how to use geckodriver with Python: Selenium install Marionette webdriver

If you want to use old Selenium driver, version 2.x:

Community
  • 1
  • 1
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
-2

These days Firefox is not doing much good with Selenium web-driver i can suggest you to use Chrome Driver instead

Download the chrome driver and extract the file. set the chrome driver path in the Environment path and then try with same code by replacing Firefox() to Chrome() or follow below code....

from selenium import webdriver

Path = ("c://chromedriver//chromedriver.exe")
browser = webdriver.Chrome(path)
#eliminate above two steps if the path is set in Environment variable 

browser = webdriver.Chrome() 

browser.get('http://www.yahoo.com')

browser.quit()
Dinu Duke
  • 185
  • 13