launch selenium from python on ubuntu
<p>I have the following script</p>

<pre><code>from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://localhost:8000')

assert 'Django' in browser.title
</code></pre>

<p>I get the following error</p>

<pre><code>$ python3 functional_tests.py 
Traceback (most recent call last):   File "functional_tests.py", line 3, in &lt;module&gt;
    browser = webdriver.Firefox()   File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__
    self.binary, timeout)   File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)   File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)   File "/usr/local/lib/python3.5/dist-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.
</code></pre>

<p><code>pip3 list</code> shows <code>selenium (2.53.6)</code>.</p>

<p><code>firefox -v</code> shows <code>Mozilla Firefox 47.0</code>.</p>

<p>I struggled with this problem as well, and I was unhappy with having to use older versions of Firefox.  Here's my solution that uses the latest version of Firefox.  It however involves several steps</p>

<p><strong>Step 1.</strong> Download v0.9.0 <em>Marionette</em>, the next generation of FirefoxDriver, from this location: <a href="https://github.com/mozilla/geckodriver/releases/download/v0.9.0/geckodriver-v0.9.0-linux64.tar.gz" rel="nofollow">https://github.com/mozilla/geckodriver/releases/download/v0.9.0/geckodriver-v0.9.0-linux64.tar.gz</a></p>

<p><strong>Step 2.</strong> Extract the file to a desired folder, and rename it to "wires".  In my case I created a folder named "add_to_system_path" under Documents. So the file is in Documents/add_to_system_path/wires (also make sure that the wires file is executable under its properties)</p>

<p><strong>Step 3.</strong> Create a file named ".pam_environment" under your home folder, and then adding this line on it and save</p>

<p><code>PATH DEFAULT=${PATH}:/absolute/path/to/the/folder/where/wires/is/saved
</code></p>

<p>What this does is it tells ubuntu to add the enumerated dir in .pam_environment to your system path </p>

<p><strong>Step 4.</strong> Save the file, log out of your user session, and log back in. This is necessary to do so that the files in the newly added system path is recognized by ubuntu</p>

<p><strong>Step 5.</strong> Use the code below to instantiate the browser instance:</p>

<pre><code>`
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

capabilities = DesiredCapabilities.FIREFOX
capabilities["marionette"] = True
browser = webdriver.Firefox(capabilities=capabilities)
browser.get('http://your-target-url')`
</code></pre>

<p>Firefox should now be able to instantiate as usual.</p>

python selenium ubuntu