Deploying Selenium
I had the misfortune of trying to use Selenium in one of my upcoming projects. Actually, Selenium is a pretty amazing tool for automating website testing, but the dependencies can be tricky to nail.
Installing on OSX is pretty straightforward:
pip install selenium
brew install chromedriver
But this became a huge nightmare for me when installing remotely. Fortunately, there is a selenium releases a docker image one can run with this one liner:
docker run -d -p 4444:4444 --name selenium --shm-size=2g selenium/standalone-chrome:3.8.1-bohrium
This is what you need to do in python:
from selenium import webdriver
# my_docker_host is usually localhost, but in Docker Toolbox is the ip of the
# virtual machine
selenium_server_url = 'http://my_docker_host:4444/wd/hub'
options = webdriver.ChromeOptions()
options.set_headless(True)
capabilities = options.to_capabilities()
driver = webdriver.Remote(desired_capabilities=capabilities,
command_executor=selenium_server_url)
# then just use the driver as you would normally
driver.get(some_url)