使用 Selenium 和无头发送密钥 Chrome
Sending keys using Selenium and headless Chrome
使用 headless chrome 和 selenium,我可以成功地将密钥发送到我 Mac 上的网站。但是,当我将相同的代码移植到我的 Linux 机器时,它崩溃了。违规行如下:
driver.find_element_by_xpath('//input[@id="username"]').send_keys(username)
我收到以下错误消息:
"an X display is required for keycode conversions, consider using Xvfb"
为什么这不适用于 Linux?
这是 chrome 驱动程序中的错误,详细说明 here。
根据 chrome 驱动程序的新线索
The issue is in ChromeDriver. As its name implies, the sendKey command sends simulated key strokes to Chrome, and ChromeDriver is responsible for converting the input text string into corresponding keystrokes to send to Chrome. On Linux, ChromeDriver uses X display to do the conversion, and fails when no X display is available.
最近已经修复,将在v 2.31中发布。遗憾的是,Chromium 团队并未公开发布每晚构建的版本,也没有正式发布日期。
在此期间您可以build your own chromedriver or download a prebuilt binary from a third party... Both a dockerfile and a working binary may be found at this github。
使用 headless chrome 和 selenium,我可以成功地将密钥发送到我 Mac 上的网站。但是,当我将相同的代码移植到我的 Linux 机器时,它崩溃了。违规行如下:
driver.find_element_by_xpath('//input[@id="username"]').send_keys(username)
我收到以下错误消息:
"an X display is required for keycode conversions, consider using Xvfb"
为什么这不适用于 Linux?
这是 chrome 驱动程序中的错误,详细说明 here。
根据 chrome 驱动程序的新线索
The issue is in ChromeDriver. As its name implies, the sendKey command sends simulated key strokes to Chrome, and ChromeDriver is responsible for converting the input text string into corresponding keystrokes to send to Chrome. On Linux, ChromeDriver uses X display to do the conversion, and fails when no X display is available.
最近已经修复,将在v 2.31中发布。遗憾的是,Chromium 团队并未公开发布每晚构建的版本,也没有正式发布日期。
在此期间您可以build your own chromedriver or download a prebuilt binary from a third party... Both a dockerfile and a working binary may be found at this github。