我正在运行一些需要在AWS实例上进行浏览器自动化的东西。我正在尝试使用虚拟显示器运行Selenium,但每当我尝试使用Selenium将键盘输入发送到页面时,我的代码就会崩溃。我可以下载源代码并在页面上查找元素,但不能使用send_keys方法。下面是MWE再现崩溃:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1920, 1080))
display.start()
driver = webdriver.Chrome()
driver.get("http://google.com")
search_field = driver.find_element_by_id("lst-ib")
search_field.send_keys("foo")
这是一个堆栈跟踪:
Traceback (most recent call last):
File "mwe.py", line 12, in <module>
search_field.send_keys(u"foo")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'
(Session info: chrome=67.0.3396.62)
(Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 4.4.0-116-generic x86_64)
到目前为止,我的Google Fu已经失败了,所以我们非常感谢任何意见。