unable to call firefox from selenium in python on AWS machine unable to call firefox from selenium in python on AWS machine python python

unable to call firefox from selenium in python on AWS machine


The problem is Firefox requires a display. I've used pyvirtualdisplay in my example to simulate a display. The solution is:

from pyvirtualdisplay import Displayfrom selenium import webdriverdisplay = Display(visible=0, size=(1024, 768))display.start()driver= webdriver.Firefox()driver.get("http://www.somewebsite.com/")<---some code--->#driver.close() # Close the current window.driver.quit() # Quit the driver and close every associated window.display.stop()

Please note that pyvirtualdisplay requires one of the following back-ends: Xvfb, Xephyr, Xvnc.

This should resolve your issue.


I too had faced same problem.I was on Firefox 47 and Selenium 2.53. So what I did was downgraded Firefox to 45. This worked.

1) Remove Firefox 47 first :

sudo apt-get purge firefox

2) 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

3) Tell which build to download

sudo apt-get install firefox=45.0.2+build1-0ubuntu1

4) Next you have to not upgrade to the newer version again.

sudo apt-mark hold firefox

5) If you want to upgrade later

sudo apt-mark unhold firefoxsudo apt-get upgrade

Hope this helps.


This is already in the comment of OP's question, but to lay it out as an answer. You can have Selenium run in the background without opening an actual browser window.

For example, if you use Chrome, set these options:

from selenium.webdriver.chrome.options import Optionschrome_options = Options()chrome_options.set_headless(headless=True)

Then when you call your web driver, your settings become a parameter:

browser = webdriver.Chrome(chrome_options=chrome_options)