Python / Selenium / Ubuntu stopped working

Hi,

I have a Python script that I have been running on Ubuntu for a few days which was working OK but is now throwing the following error.

    driver = webdriver.Firefox()                                                                                                                                                        
  File "/usr/local/lib/python3.4/dist-packages/selenium-2.45.0-py3.4.egg/selenium/webdriver/firefox/webdriver.py", line 59, in __init__                                                 
    self.binary, timeout),                                                                                                                                                              
  File "/usr/local/lib/python3.4/dist-packages/selenium-2.45.0-py3.4.egg/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__                                      
    self.binary.launch_browser(self.profile)                                                                                                                                            
  File "/usr/local/lib/python3.4/dist-packages/selenium-2.45.0-py3.4.egg/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser                                      
    self._wait_until_connectable()                                                                                                                                                      
  File "/usr/local/lib/python3.4/dist-packages/selenium-2.45.0-py3.4.egg/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.  

Open in new window


I reinstalled the OS and it worked again for a while and is now doing the same.

The browser window doesn't launch any more when the script starts.

Can anyone help?
LVL 2
aidebAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gelonidaCommented:
A few small questions:
- which version of ubuntu
- which version of python
- do you use virtualenv: If yes:
    - which of the options do you use: --system-site-packages --no-site-packages


I am using ubuntu 12.04 or higher, python 2.7, virtualenv (with --system-site-packages)  and selenium.

Very often after a system update.  selenium is no more working.
In my case it is probably because of the switch --system-site-packages, which I need due to some reasons.
In my case recreating a new virtualenv solves the problem.
aidebAuthor Commented:
Hi,

Ubuntu version - Ubuntu 14.04.2 LTS
Python3
No virtualenv in use

Perhaps I should look at virtualenv? - I have no experience of how it works
gelonidaCommented:
Seems to be a different problem than mine :-(
At least I was convinced, that my problem was, that I was using virtualenv. but you seem to have issues without virtualenv.

I'm not sure that virtualenv will solve any problems.
The only thing could be, that if the problem occurs it will be easier to fix.
(Just delete the virutalenv and create a new one)

At least for me selenium always started working when I created a new virtualenv,


Virtualenv allows you to have different versions of python with different packages on the same machine.
it's good for debugging or when one script requires one version of a package and another script requires another version.

However often virtualenv will try to compile more complex python packages, so you must have gcc, the build essentials and depending on the package you'd like to install some -dev packages installed.


quick way to try  out:

pip3 install virtualenv # install virtualenv or python3
virtualenv -p `which python3` ~/mypy3 # create a virtualenv for python3 in ~/mypy3
source ~/mypy3/bin/activate # enable the virtualenv. ALWAYS type this to enable a virtualenv
pip install selenium # this might cause errors I don't know all dependencies of selenium

Open in new window


If the last command fails I'd need the error output to advise what's going wrong.
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

aidebAuthor Commented:
I read an article that explained how to set up virtualenv and gave it a go - its pretty much as you explained. I had to install all the prerequesties for the script again however I am left with the exact same issue.

bah.....any other suggestions?
gelonidaCommented:
hmm.
just for testing: Could you close all existing firefox instances.
and check that really no other firefox is running:
ps axu | grep firefox

Open in new window

you might check with  apt-get / aptitude / synaptics, whether your firefox is up to date
before retrying.

Do I understand you correctly that following code snippet is enough to make you fail:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.experts-exchange.com/Programming/Languages/Scripting/Python/Q_28667793.html#a40760131")

Open in new window


Unfortunately I have an older Ubuntu version and can't check on my machine.

Do you have the same problem if you're using python 2.7?
aidebAuthor Commented:
I have just checked and yes, all firefox instances are closed

The version of firefox was out of date however it has made no difference

Trying Python 2.7 makes no difference either.

Your code generates the same error... :(
gelonidaCommented:
Is your DISPLAY variable correct.
echo $DISPLAY

Open in new window

Can you start any other graphical application from this bash shell (e.g)
gnome-terminal

Open in new window


The error message:
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.  

suggests, that there might be a way to create a log file containing more details.
Unfortunately I don't know how,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aidebAuthor Commented:
Hi,

I couldn't do as suggested so i rebooted and tried again - Bingo! it worked...tried my script again and it is also working again.

Not sure why though which is not good....but thanks for all your help!
aidebAuthor Commented:
Thanks again for your help!
gelonidaCommented:
Good luck.

Next time this error occurs:
Please check the DISPLAY vars and whether you can start another application requiring an Xwindows display.

Your error message occurs often if no display is present.
aidebAuthor Commented:
Top tip! Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.