Using selenium with headless browser

My note about setting selenium

First install virtual display

# install virtual display xvfb
$> sudo apt-get install xvfb xserver-xephyr
# install PyVirtualDisplay which is python wrapper for xvfb
$> sudo pip install pyvirtualdisplay
# install selenium python driver
$> sudo pip install selenium

Second install selenium, google chrome and chromedriver on linux

# selenium server
$> curl -O
# selenium chrome driver
$> curl -O
$> unzip
# move chromedriver to /usr/bin, so next time you start selenium server, chromedriver will be loaded
$> sudo mv chromedriver /usr/bin
# install chrome on debia
$> sudo apt-get install chromium-browser chromium-browser-110n

Next, start selenium server

$> java -jar /home/<user_name>/selenium-server-standalone-2.24.1.jar 2>&1 > /dev/null &

Now, when write code to run chrome headless

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))

browser = webdriver.Chrome()
print browser.title


Kien Nguyen Trung

A father, husband and Elixir lover.

Ho Chi Minh, Vietnam