Forums

The browser appears to have exited error

Getting an error using selenium webdriver. Have the following code -

# A very simple Flask Hello World app for you to get started with...
from pyvirtualdisplay import Display
from selenium import webdriver
from flask import Flask
import time

app = Flask(__name__)


@app.route('/')
def hello_world():
    with Display():
         # we can now start Firefox and it will run inside the virtual display
        browser = webdriver.Firefox()

     # put the rest of our selenium code in a try/finally
     # to make sure we always clean up at the end
        try:
            browser.get('http://www.google.com')
            return 'worked'
        finally:
            browser.quit()

[edit by admin: formatting]

That's odd, your code certainly looks OK to me. Could you try adding the parameter

log_path='/tmp/geckodriver.log'

...to the webdriver.Firefox() call, and reload your site? It should then write out some details of what went wrong to that file.