1

So here's my setup:

Using a flask server with uwsgi, and through a controller action, calling a python script that uses splinter (which uses selenium) to automate the gui. The web server doesn't have a display, so I'm using xvfb.

Sshing into the machine and running xvfb and exporting display=:99, and then running the python script works great. But running it through a controller action does not work - I get the following error:

WebDriverException: Message: The browser appears to have exited before we could connect.

(this is the same error that is returned when xvfb isn't running)

ps aux shows that xvfb is running as the same user as the web server (I've isolated everything, and have a separate controller action that executes:

p = subprocess.Popen("Xvfb :99 &", stdout=fstdout,stderr=fstderr, shell=True))

and DISPLAY is set to :99 on both root and the web server user.

I could install vncserver and try that, but I suspect I will end up with the same problem. I've also tried to avoid calling xvfb directly and using PyVirtualDisplay instead, but same problem.

edit: it errors on this line (if using splinter):

browser = Browser()

or, if selenium:

with pyvirtualdisplay.Display(visible=True):

    binary = FirefoxBinary()
    driver = webdriver.Firefox(None, binary)

(it errors on the last line there)

Any ideas?

  • Please include in your question your Selenium script, at least up to the point where the problem occurs. Otherwise, we're guessing. – Louis Dec 09 '14 at 23:21
  • I don't technically use Selenium directly--instead, I use splinter, and it errors here: browser = Browser() (which sets up the firefox selenium webdriver) – StackOverflow_Name Dec 09 '14 at 23:25
  • Sounds like you ran into the issue I've [answered here](http://stackoverflow.com/questions/27202131/firefox-started-by-selenium-ignores-the-display-created-by-pyvirtualdisplay). – Louis Dec 09 '14 at 23:28
  • Interesting idea--I tried it, and it freezes--this is a separate issue that I left out to make things simpler, but if I use PyVirtualDisplay or even subprocess.popen (xvfb) in the same script in which I will later do the gui automation, it just hangs, and even restarting uwsgi does nothing--i have to reboot the webserver entirely to be able to interact with it again. edit--I did also try executing a separate thread before running PyVirtualDisplay or popen--and have also tried that with running the app using app.run(threading=True) – StackOverflow_Name Dec 09 '14 at 23:38
  • edit #2: after rebooting, i isolated anything else that may be going on, and just used your idea (without executing xvfb independently etc)--this fixed the freezing, but I'm still left with "WebDriverException: Message: The browser appears to have exited before we could connect. ", which fails on " driver = webdriver.Firefox(None, binary)" – StackOverflow_Name Dec 09 '14 at 23:45
  • Any other ideas? Sorry to bug. – StackOverflow_Name Dec 10 '14 at 20:36
  • Nope and the reason I do not have any other ideas is in my first comment. – Louis Dec 10 '14 at 20:38
  • Hi Louis--I appreciate your help--it errors on this line "browser = Browser()" or if you'd prefer, with pyvirtualdisplay.Display(visible=True): binary = FirefoxBinary() driver = webdriver.Firefox(None, binary) (it errors on driver = webdriver.Firefox(None, binary) there)--assume these are at the beginning of the script (edit--I added to original question to make it easier) – StackOverflow_Name Dec 11 '14 at 19:03

0 Answers0