2

I have a simple python script that works fine on my local machine. But if I try to run it on my vps I get an error:

Traceback (most recent call last):
  File "test.py", line 15, in <module>
    browser = webdriver.Firefox(profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
    self.binary, timeout),
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
    self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
    raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

And here is the script:

from selenium import webdriver

profile = webdriver.FirefoxProfile()

profile.set_preference('permissions.default.image', 2)
# Set all new windows to open in the current window instead
profile.set_preference('browser.link.open_newwindow', 1)
browser = webdriver.Firefox(profile)
browser.get('http://www.google.com/')
html = browser.page_source

print html

browser.close()

Since there is no GUI for the vps is that what is causing the error?

Rodrigo
  • 3,129
  • 3
  • 33
  • 61
  • 1
    http://stackoverflow.com/questions/27270337/how-to-fix-webdriverexception-the-browser-appears-to-have-exited-before-we-coul – Rajarshi Das Jan 10 '16 at 06:09
  • @RajarshiDas: So, this question should be a dupe. Why don't vote to close instead of post a comment? – Remi Guan Jan 10 '16 at 07:03

1 Answers1

4

You have to use xvfb package to run webdriver correctly.

usr/bin/xvfb-run /usr/bin/python myfile.py

Check This link for more detail

Ali Nikneshan
  • 3,500
  • 27
  • 39