Forums

Selenium not working

Hi,

I am trying to run Selenium in a web app but my error log is returning the following error:

selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: b"\n(process:14015): GLib-CRITICAL **: g_slice_set_config: assertion \'sys_page_size == 0\' failed\nError: no display specified\n"'

I am already attempting to use xvfb, I have tried to run it in the bash console for my web app - 15:26 ~/mysite $ xvfb-run python bottle_app.py

My python code is as follows:

from bottle import default_app, route
from selenium import webdriver
import time

@route('/')
def hello_world():
    return 'Hello from Bottle!'

@route('/test')
def test():
    browser = webdriver.Firefox()
    browser.get("http://google.com")
    time.sleep(2)
    title = browser.title
    return title

application = default_app()

Thanks so much in advance!!

You need to use a virtual display.

Also as a free user you will be limited to just http/https connections to whitelisted sites.

Hi Conrad,

Thanks so much for replying!

I actually saw that post and I tried what was described in it to no avail.

As I am using Python 3.3, I also created a virtualenv so that I could install and import pyvirtualdisplay.

However, I am now getting the error message I have included below.

I have a web app that I am almost ready to deploy and I would be ready to sign up as a paid user the moment I can get this resolved. However, I really need Selenium to work for my web app to work, so this has been quite frustrating. Thanks so much for trying to help though :)

My code is now as follows:

#A very simple Bottle Hello World app for you to get started with...
from bottle import default_app, route
from pyvirtualdisplay import Display
from selenium import webdriver
import time

display = Display(visible=0, size=(800, 600))
display.start()

@route('/')
def hello_world():
    return 'Hello from Bottle!'

@route('/test')
def test():
    browser = webdriver.Firefox()
    browser.get('http://www.google.com')
    return browser.title


application = default_app()

This is the error message that I retrieved from the error log:

2016-08-30 17:07:36,192 :Error running WSGI application
Traceback (most recent call last):
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
  File "/bin/user_wsgi_wrapper.py", line 154, in __call__
    app_iterator = self.app(environ, start_response)
  File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
    raise e
  File "/bin/user_wsgi_wrapper.py", line 179, in <module>
    application = load_wsgi_application()
  File "/bin/user_wsgi_wrapper.py", line 175, in load_wsgi_application
    return __import__(os.environ['WSGI_MODULE'], globals(), locals(), ['application']).application
  File "/var/www/mforcexxii_pythonanywhere_com_wsgi.py", line 22, in <module>
    from bottle_app import application
  File "/home/mforcexxii/mysite/bottle_app.py", line 8, in <module>
    browser = webdriver.Firefox()
  File "/home/mforcexxii/.virtualenvs/myvirtualenv/lib/python3.3/site-packages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "/home/mforcexxii/.virtualenvs/myvirtualenv/lib/python3.3/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/home/mforcexxii/.virtualenvs/myvirtualenv/lib/python3.3/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/home/mforcexxii/.virtualenvs/myvirtualenv/lib/python3.3/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 99, in _wait_until_connectable
    "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.

Update:

I decided to implement a workaround instead of trying to solve this. Instead of using Selenium, I am now using urllib.request.

Everything seems to be working fine now!

Also I created a new account because for some reason the server kept returning an unhandled exception (even for the hello world test page) no matter what I did to try to fix it.

May I know how I can delete my previous account mforcexxii?

Send us feedback when you're logged in to the account and ask for the account to be deleted.