Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix WebDriverException: The browser appears to have exited before we could connect? [duplicate]

In my Linux system I use Firefox, execute my program, the error which I've is:

Traceback (most recent call last):

File "shenma_diff_main_v2.py", line 90, in <module>
    browser = webdriver.Firefox(profile)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.binary, timeout),
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
    self._wait_until_connectable()
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, 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.

If I use root execute my program is OK.

like image 435
laubond Avatar asked Dec 03 '14 11:12

laubond


1 Answers

This is because you did not set up correctly to run Firefox without GUI. This is a tutorial that might be helpful Selenium Headless Automated Testing in Ubuntu

I think the reason is you need to specify the port number, probably xvfb runs on a different port than Firefox on one terminal:
xvfb :99 -ac
on the another terminal:
export DISPLAY=:99
and run your scrapy program I am successful without using root

like image 101
user3722836 Avatar answered Nov 15 '22 15:11

user3722836