擅长:python、mysql、java
<p>我不知道为什么会发生这种情况,但是这个错误与Firefox驱动程序使用“本地事件”进行用户交互模拟(键盘、鼠标等)有关。</p>
<p>有关本机事件的一些技术详细信息和背景/问题,请参阅:
<a href="https://code.google.com/p/selenium/wiki/NativeEventsOnLinux" rel="nofollow noreferrer">https://code.google.com/p/selenium/wiki/NativeEventsOnLinux</a></p>
<p>许多selenium用户(包括我自己)发现,“本地事件”在许多情况下都是有问题的,而使用“合成事件”则更容易/更安全。合成事件通过JavaScript模拟用户交互。</p>
<p>因此,尝试在驱动程序中禁用本机事件(通过设置profile属性),这样就可以避免该错误。</p>
<p>示例:</p>
<pre><code>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.
</code></pre>