Using Selenium on Raspberry Pi headless Using Selenium on Raspberry Pi headless python python

Using Selenium on Raspberry Pi headless


This works for me on Raspberry Pi headless:

Installation:

sudo apt-get install python-pip iceweasel xvfbsudo pip install pyvirtualdisplay selenium

Code:

from selenium import webdriverfrom pyvirtualdisplay import Displaydisplay = Display(visible=0, size=(800, 600))display.start()driver = webdriver.Firefox()


I'm not sure why it is happening, but that error you are getting has to do with the Firefox driver using "native events" for user interaction simulation (keyboard, mouse, etc).

For some technical details and background/issues with native events, see:https://code.google.com/p/selenium/wiki/NativeEventsOnLinux

Many selenium users (myself included) find that "native events" are problematic in many situations, and it's just easier/safer to use "synthesized events" instead. Synthesized events emulate user interaction via JavaScript.

so, try disabling native events (by setting the profile property) in your driver and you should get past that error.

Example:

from selenium import webdriverprofile = webdriver.FirefoxProfile()profile.native_events_enabled = Falsedriver = webdriver.Firefox(profile)# synthesized events are now enabled for this # driver instance... native events are disabled.