1# credit to the Stack Overflow user in the source link
2
3sudo apt-get install xvfb
4pip install pyvirtualdisplay
5
6#!/usr/bin/env python
7from pyvirtualdisplay import Display
8from selenium import webdriver
9
10display = Display(visible=0, size=(800, 600))
11display.start()
12
13# Now Firefox will run in a virtual display.
14# You will not see the browser.
15browser = webdriver.Firefox()
16browser.get('http://www.google.com')
17print(browser.title)
18browser.quit()
19display.stop()