Using Selenium on Raspberry Pi headless

我是研究僧i 提交于 2019-11-29 22:30:09

This works for me on Raspberry Pi headless:

Installation:

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

Code:

from selenium import webdriver
from pyvirtualdisplay import Display

display = 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 webdriver

profile = webdriver.FirefoxProfile()
profile.native_events_enabled = False
driver = webdriver.Firefox(profile)
# synthesized events are now enabled for this 
# driver instance... native events are disabled.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!