I am trying to run selenium webdriver on my droplet, and after days of unsuccessful attempts, I need some help. Here’s what I have done:

Hooked up a display:

from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start()

Here’s where it chokes for Chrome:

b = webdriver.Chrome() #doesn’t choke yet, but definitely hangs for longer than normal..
b
<selenium.webdriver.chrome.webdriver.WebDriver (session=“7725d000781011a8e713a7fd722361b4”)>
b.get(’https://www.google.com’) #and there it is…

selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreated has invalid ‘context’: {“auxData”:{“frameId”:“1342.1”,“isDefault”:true},“id”:1,“name”:“”,“origin”:“://”}
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.9.248304,platform=Linux 4.4.0-59-generic x86_64)

And here’s where it chokes for Firefox:

b = webdriver.Firefox()
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 2

I have tried at least 4 versions of different chrome drivers. I have selenium working on my personal box (I use Chrome) with this similar setup, but I don’t use/need the display. I am running the cheap droplet, 512mb, 5$, but I resized it to 4 GB of memory and it still fails, so its not there?

Thank you very much.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

I wasn’t playing with Selenium a lot, but AFAIK, it does require you GUI, to run browser.
Error doesn’t appear to share a lot information, but if you don’t have any UI on server that can be a problem.

In case this is a problem, you can checkout headless mode and headless browser.
It let’s you use browser from a CLI.
There is no tutorial here, but I found one Medium article - Running Selenium WebDriver tests using Firefox headless mode on Ubuntu.
Also, you can play around VNC and setup GUI on the server, that way.

by finid
In this guide, we will be setting up VNC on a Ubuntu 16.04 server and connecting to it securely through an SSH tunnel. The VNC server we will be using is TightVNC, a fast and lightweight remote control package. This choice will ensure that our VNC connection will be smooth and stable even on slower internet connections.
  • Thanks for the response. I tried the tutorial for the headless Firefox with no success. There seems to be a driver issue when I try and run Firefox after launching xvfb. Do I need a special driver installion, you think, on my droplet for headless Firefox to work?

Submit an Answer