Apparently it's common for google-chrome to get this: http://jira.openqa.org/browse/SRC-740
The key is to start it without security enabled. To disable security,
"--disable-web-security",
I'm having trouble wondering how to actually specify these command line arguments, though, so it fails on the open invocation here:
from selenium import selenium
sel = selenium('localhost', 4444, '*googlechrome', 'http://www.google.com/')
sel.start()
sel.open('/')
Here's how I start the selenium server:
shogun#box:~$ java -jar selenium-server-standalone-2.0b3.jar
To get this to work, I had to create an external script to wrap the chrome browser. Place a script somewhere your Selenium server can reach it (mine is at ~/bin/startchrome, and chmod it executable:
#!/bin/sh
# chrome expects to be run from the .app dir, so cd into it
# (the spaces in the path are a Mac thing)
cd /Applications/Google\ Chrome.app
exec ./Contents/MacOS/Google\ Chrome --disable-security $*
Then in your Python code, do this:
from selenium import selenium
browser = '*googlechrome /Users/pat/bin/startchrome'
sel = selenium('localhost', 4444, browser, 'http://www.google.com')
sel.start()
sel.open('/')
Related
Running Ubuntu 20.04 LTS server
Trying to save a screenshot via selenium within a flask route.
Issue is no matter what I try it crashes.
Using --headless
#api.route('/image/<path:encoded_url>.png')
def generate_image(encoded_url):
"""
Returns an image (PNG) of a URL. The URL is encoded in the path of the image being requested.
"""
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True
options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-using")
driver = webdriver.Chrome(f"{os.getcwd()}/chromedriver", options=options)
url = urllib.parse.unquote_plus(encoded_url)
driver.get(url if "http" in url else "https://" + url)
driver.set_window_size(1200, 630)
while True:
x = driver.execute_script("return document.readyState")
if x == "complete":
break
driver.save_screenshot("screen.png")
driver.close()
return send_file("screen.png", mimetype='image/png')
I've tried everything but firefox exits with error 127 (not much online regarding this)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 127
I've tried running with Xvfb with no luck.
Ok, so after trying a whole load of options it turns out the issue was with my setup of gunicorn.
go to
cd /etc/systemd/system/
open the service you made for guinocorn
sudo nano {servicename}
The issue was the Environment line
Originally I has it as this:
Environment="PATH=/home/ubuntu/retrotex/environment/bin"
But once I changed it to the below everything worked:
Environment="PATH=/home/ubuntu/retrotex/environment/bin:/usr/bin:/bin"
It seems that flask didn't have access to the folders needed to run chome or selenium.
Make sure you run the below to reload the service after
sudo systemctl daemon-reload
sudo systemctl restart {service_name}
What a waste of a day.
Server: Raspberry Pi 3
OS: Dietpi - version 159
Geckodriver version: 0.22 for arm
Firefox version: 52.9.0
Python version: 3.5
Selenium version: 3.14.1
Gecko is executable, and is located in /usr/local/bin/
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
import time
options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_options=options)
print('Need your login credential')
username = input('What is your username?:\n')
password = input('What is your password?:\n')
...
...
Output:
root#RPi3:~# python3.5 ITE-bot.py
Traceback (most recent call last):
File "ITE-bot.py", line 12, in <module>
driver = webdriver.Firefox(firefox_options=options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
Any idea what is wrong? I've tried google without luck.
If you are running Firefox on a system with no display, make sure you use headless mode.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
Also, make sure you have compatible versions of Firefox, Selenium, and Geckodriver:
https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html
Thumb rule
A common cause for Browsers to crash during startup is running WebDriver initiated Browsers as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Browser as a regular user instead.
This error message...
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowsing Session i.e. Firefox Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
Your GeckoDriver version is 0.22.0.
Release Notes of GeckoDriver v0.21.0 (2018-06-15) clearly mentions the following:
Firefox 57 (and greater)
Selenium 3.11 (and greater)
Your Firefox version is 52.9.0.
So there is a clear mismatch between GeckoDriver v0.22.0 and the Firefox Browser v57
Solution
Upgrade GeckoDriver to GeckoDriver v0.22.0 level.
GeckoDriver is present in the specified location.
GeckoDriver is having executable permission for non-root users.
Upgrade Firefox version to Firefox v62.0.2 levels.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Execute your Selenium Test as a non-root user.
GeckoDriver, Selenium and Firefox Browser compatibility chart
I was on headless mode, using correct versions of everything, and the only way to get out of this error message was not to execute the selenium test as root
Yes checked Start Xvfb before the build can fix the problem, but if you have a job like a pipeline or multibranch pipeline this option is not visible. In the node of your Selenium grid that you go to execute the test you need:
1- Install Xvfb: apt install xvfb
2- Execute Xvfb: /usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99"
3- Rerun your node, for example: java -jar selenium.jar -role node -hub http://#.#.#.#:4444/grid/register -capabilities browserName=firefox,plataform=linux -host #.#.#.# -port 1991
This solution worked for me
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
As there can be many different underlying causes for this error it is best to find the root cause setting selenium to use debug level logging. In my case, for Ruby with capybara I needed to set: Selenium::WebDriver.logger.level = :debug. And voilĂ , running the same spec I could see in the logs that a dependency was missing, in my case:
libdbus-glib-1.so.2: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
After installing it all worked fine.
I used:
VS Code
Linunx/Ubuntu:18.10
Nightwatch.js
My problem was that I tried to run Nightwatch (which automatically starts GeckoDriver) from the VS Code terminal.
I had the same problem, and realized that the real problem was some firefox dependencies not being installed inside the docker container I was testing in.
Try to initiate firefox and check if it returns an error.
As Nico and jay have stated you need to check the logs to see the details of the error. As you might use different systems, you can specify the path where the log is stored (i.e. "/tmp/geckodriver.log").
from selenium import webdriver
firefox_options = webdriver.firefox.webdriver.Options()
driver = webdriver.Firefox(log_path="/tmp/geckodriver.log",
options=firefox_options)
In my particular case, what the log said was:
Error: no DISPLAY environment variable specified
That was resolved adding in the options the headless mode before starting the driver. With the line:
firefox_options.set_headless()
I was able to fix this by running my tests with Xvfb. I was running them on a remote server.
I was using Jenkins so I checked the box that looked like this:
Credit to https://www.obeythetestinggoat.com/book/chapter_CI.html
in my case, I was running test cases as root
geckodriver.log
1576076416677 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenCbl2e"
Running Firefox as root in a regular user's session is not supported. ($HOME is /home/seluser which is owned by seluser.)
1576077143004 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile7wpSQ7"
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: telemetry
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1576077145372 Marionette INFO Listening on port 35571
1576077145423 Marionette WARN TLS certificate errors will be ignored for this session
1576077200207 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenhoHlr"
Running Firefox as root in a regular user's session is not supported. ($HOME is /home/seluser which is owned by seluser.)
i could get around by
cd /home
chown -R root seluser
i woundnt say its correct but it got my job done
I am trying to use the geckodriver with firefox and selenium on my Ubuntu machine. This is the code I have so far:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
#path where browser is installed
binary = '/usr/bin/firefox'
options = webdriver.FirefoxOptions()
options.binary = binary
options.add_argument('start-maximized')
options.add_argument('--headless')
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
path_to_driver = "/home/andrea/geckodriver"
# run firefox webdriver from executable path
driver = webdriver.Firefox(firefox_options=options, capabilities=cap, executable_path = path_to_driver)
#driver = webdriver.Firefox(capabilities=cap, executable_path = path_to_driver)
driver.get("https://www.amboss.com/us/account/login")
Despite that I am getting the following error:
selenium.common.exceptions.WebDriverException: Message: Can't load the profile.
Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpuigrk9f7 If you specified a log_file in the FirefoxBinary constructor, check it for details.
The firefox version which I work with is:
Mozilla Firefox 68.0.2
Does anyone have any idea as to how I could go about fixing this?
Step1: Install Selenium
Type in Terminal(in Ubuntu) or in Command Prompt(in Windows)
$pip install selenium
Step2: Download Geckodriver
In order to work with Selenium there should be an executable called 'Gecko Driver' installed.
Download Gecko Driver from the following page:
https://github.com/mozilla/geckodriver/releases
Step3: Install Gecko Driver
Latest version for Windows:
https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-win64.zip
Latest version for Ubuntu:
https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
Setup Gecko Driver For Windows:
Extract the zip file and move the geckodiver.exe executable file to any location which is already in Path variable(For Example you can move it to Python path location)
Unless add the path of 'geckodriver.exe' to the Path variable
Setup Gecko Driver For Ubuntu:
Open Terminal
Ctrl+Alt+T
move directory to the location where tar file is downloaded
Usually it will be in Downloads. so type $ cd Downloads
Unzip the tar file
eg:
$sudo tar -xvf filename.tar.gz
In my case it is:
$sudo tar -xvf geckodriver-v0.26.0-linux64.tar.gz
Move the geckodriver executable file to the '/usr/local/bin' location
$sudo mv geckodriver /usr/local/bin/
Move the directory to '/usr/local/bin/'
$cd /usr/local/bin/
Now make executable permission for 'geckodriver' executable file
$sudo chmod +x geckodriver
Now type 'geckodriver' in Terminal
geckodriver
If Gecko Driver is not working still then add its path
$export PATH=$PATH:/usr/local/bin/geckodriver
Now it is ready to work with selenium
Sample Code
Some sample codes are here:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import ui
driver = webdriver.Firefox()
driver.get('https://www.google.com/')
page_url=driver.find_elements_by_xpath("//a[#class='content']")
all_title = driver.find_elements_by_class_name("title")
title = [title.text for title in all_title]
print(title)
This error message...
selenium.common.exceptions.WebDriverException: Message: Can't load the profile.
Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpuigrk9f7 If you specified a log_file in the FirefoxBinary constructor, check it for details.
...implies that there was a mismatch between the GeckoDriver and Firefox version while initiating/spawning a new WebBrowsing Session i.e. Firefox Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using Mozilla Firefox v68.0.2
Your Selenium Client version is is unknown to us.
Your GeckoDriver version is unknown to us.
However as you are using Mozilla Firefox v68.0.2, using GeckoDriver is mandatory and while you use GeckoDriver you can't set the capability marionette as False.
You can find a detailed discussion in How can Geckodriver/Firefox work without Marionette? (running python selenium 3 against FF 53)
Solution
Upgrade Selenium to current levels Version 3.141.59.
Upgrade GeckoDriver to current GeckoDriver v0.24.0 level.
GeckoDriver is present in the specified location.
GeckoDriver is having executable permission for non-root users.
Upgrade Firefox version to Firefox v68.0.2 levels.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your Test as a non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Outro
GeckoDriver, Selenium and Firefox Browser compatibility chart
If you want to use Firefox with Selenium, you need to import e Firefox Profile. You can use your own Profile through the following steps :
Locate the Firefox Profile directory
You have to specify the absolute path of the Firefox Profile directory when you initiate the webdriver.
from selenium import webdriver
profile = webdriver.FirefoxProfile(*path to your profile*)
driver = webdriver.Firefox(firefox_profile=profile)
I have installed firefox and Xvfb on my centos6.4 server to use selenium webdriver.
But, when I run the code, I got an error.
from selenium import webdriver
browser = webdriver.Firefox()
Error
selenium.common.exceptions.WebDriverException: Message:
'The browser appears to have exited before we could connect. The output was: None'
I read some related pages on stackoverflow and someone suggested to remove all files in tmp folder, so I did it. But, it still doesn't work.
Could anyone please give me a help?
Thank you in advance!
Edit
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 64, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 103, in _wait_until_connectable
self._get_firefox_output())
selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: None'
for Googlers, this answer didn't work for me, and I had to use this answer instead. I am using AWS Ubuntu.
Basically, I needed to install Xvfb and then pyvirtualdisplay:
sudo apt-get install xvfb
sudo pip install pyvirtualdisplay
Once I had done that, this python code worked:
#!/usr/bin/env python
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start()
browser = webdriver.Firefox()
browser.get('http://www.ubuntu.com/')
print browser.page_source
browser.close()
display.stop()
Thanks to #That1Guy for the first answer
I was running into this on an (headless) Ubuntu 14.04 server with Jenkins and xvfb installed. I had installed the latest stable Firefox (47) which started a build failing that ran a python script which used the Firefox driver for selenium (version 2.53).
Apparently Firefox 47+ is not compatible with the driver used in Selenium 2.53, and Selenium 3+ will be using a new driver called "Marionette" or "Gecko Driver" (which isn't officially released yet).
This page explains how to use the new driver pretty well, in several languages: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
Basically:
get/build the executable from the project on github: https://github.com/mozilla/geckodriver/releases (and make sure it's perms are set to be executable, IE chmod a+x /path/to/geckdriver-executable)
rename/copy binary to "wires"
make sure the binary's location is added to the PATH that the build uses when executing the selenium test
update the selenium test to use the new driver
For Python, step 4 looked something like the following for me:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/usr/bin/firefox'
driver = webdriver.Firefox(capabilities=firefox_capabilities)
I too had faced same problem. I was on Firefox 47 and Selenium 2.53; I downgraded Firefox to 45. This worked.
Remove Firefox 47 first :
sudo apt-get purge firefox
Check for available versions:
apt-cache show firefox | grep Version
It will show available firefox versions like:
Version: 47.0+build3-0ubuntu0.16.04.1
Version: 45.0.2+build1-0ubuntu1
Install a specific version
sudo apt-get install firefox=45.0.2+build1-0ubuntu1
Next you have to not upgrade to the newer version again.
sudo apt-mark hold firefox
If you want to upgrade later
sudo apt-mark unhold firefox
sudo apt-get upgrade
Check your DISPLAY environment variable. Run echo $DISPLAY in the command line.
If nothing is printed, then you are running FireFox without any DISPLAY assigned. You should assign one! Run export DISPLAY=:1 in the command line before running your python script.
Check this thread for more information: http://hashcat.net/forum/thread-1973.html
I think the simplest solution here is just run Python with xvfb-run:
sudo apt-get install xvfb
xvfb-run python <your_file_or_args>
Rollback your Firefox to the previous working version. I suggest 2 versions back. Disable Firefox Maintenance Service.
I was working on a solution and the Firefox Maintenance Service updated Firefox to the latest build in the background. This broke my code and it was giving me this error.
Now it is fixed!
Thank you everyone!
This error is due to your Xvfb is not running. So restart your xvfb:
Xvfb :99 -ac
then check.
This works for me.
Instead of downgrading firefox from 47 version to 45 or something I'll suggest to upgrade to 47.0.1 or above since they seem to fix an issue.
But if your OS doesn't have new packages in repo (for example Ubuntu 14.04 in time of this answer), you can use debs from ubuntuzilla project:
wget sourceforge.net/projects/ubuntuzilla/files/mozilla/apt/pool/main/f/firefox-mozilla-build/firefox-mozilla-build_47.0.1-0ubuntu1_amd64.deb
sudo dpkg -i firefox-mozilla-build_47.0.1-0ubuntu1_amd64.deb
For x86 use _i386.deb postfix.
That sold problem for me
I fixed this by running a recursive chown against not only the python script using selenium, but against the entire virtualenv that script was running in. I changed the ownership to the user running the file. After that, this error went away.
I also faced the same issue, what I did was:
Upgrade selenium package
sudo pip install -U selenium
Instead of rolling back to older version(like suggested) I rolled up to newer version(48.0, I was previously using V47.0).
(for upgrading follow the instructions given by Toby Speight but instead of choosing older version choose newer version)
I found this solution on Windows 10 Build 18363. I had to call out specifically the Firefoxbinary and the geckdriver executable path.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX.copy()
caps['marionette'] = True
# Path to Firefox binary
binary = FirefoxBinary(r'C:\Program Files\Mozilla Firefox\firefox.exe')
# Browser (driver) binary assigned, capabilities, and executable path for the geckodriver
driver = webdriver.Firefox(firefox_binary=binary, capabilities=caps,
executable_path=r'C:\Users\<name>\python\python-projects\geckodriver-v0.28.0-win64\geckodriver.exe')
# get google.co.in
driver.get("https://google.com")
update your selenuim version ---> pip install -U selenium
It can be solved by changing the file permission of the output file ( or related files to the program).
I used Firefox's webdriver.
Try:
chmod -R 777 output_file
This solved me the same trouble you have.
I have a python method that sets up a browser in headless-mode on a linux server for website scraping with selenium. The display gets setup perfectly fine regardless of which user executes the python script but if the sudo user doesn't execute the script it will hang at the webdriver.Firefox() setup line indefinitely.
Here is the full method:
def browserSetup(self, browser=None):
try:
# now Firefox will run in a virtual display. you will not see the browser.
self.display = Display(visible=0, size=(800, 600))
self.display.start()
if self.verbose:
print "Virtual display started for browser instantiation."
#change user agent
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1")
profile.set_preference("webdriver.log.file", "webdriver.log")
# Create a new instance of the Firefox driver
browser = webdriver.Firefox(profile)
if self.verbose:
print "Browser window object established # %s." % browser
return browser
except Exception, e:
raise e
So, to repeat my issue: if the script is not executed as sudo then the script will hang indefinitely at the webdriver.Firefox creation line. Why would this be happening?
UPDATE: The problem is this line here:
browser = webdriver.Firefox() #with or without the profile variable - the results are the same
UPDATE AGAIN
Several people in the comments below have suggested I try running Firefox from the command line manually to see if there are any issues; here are the results:
#initialize the virtual display
$ sudo Xvfb :10 -extension RANDR
[dix] Could not init font path element /usr/share/fonts/X11/cyrillic, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/100dpi/:unscaled, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/75dpi/:unscaled, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/Type1, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/100dpi, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/75dpi, removing from list!
[dix] Could not init font path element /var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType, removing from list!
#now start firefox in another ssh window (since the Xvfb process is consuming my prompt)
$ export DISPLAY=:10
$ firefox
(firefox:6347): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
//bin/dbus-launch terminated abnormally without any error message
The last error message displays hundreds of times...
I can only guess, but here's what I suspect.
sudo clears your environment variables when you start Firefox via it. That includes the DISPLAY variable as well.
Two ways to disable this behavior:
- Disable env_reset in your sudoers configuration.
- Use sudo -i, that will preserve the value of DISPLAY.
First you need to start the Xvfb (virtual frame-buffer X server) in the background.
For example, $ sudo Xvfb :1 & or $ sudo Xvfb :1 -screen 0 1280x1024x8.
Then, whenever you want to run your script, do it with the DISPLAY environment variable set accordingly.
For example, $ DISPLAY=:1 python your_script.py.
You may not want to open usr/lib up for good but try testing it with open perms on the directory.
sudo chmod 755 /usr/lib
If that's the issue, you can always move the drivers inside your application. Unless you're sharing them with many people, they're small enough to have several copies.
For anyone else like me that until today could be having this problem:
For me was due to Firefox needs to be able to create a profile, which is created at the user home folder. The user i created didn't had its own user home folder so when i created it the problem was solved.