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 Display
from selenium import webdriver

display = 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.

Leave a Comment