python 3.6 selenium webdriver错误X显示是无法发送到ues的发送键所必需的Xvfb [英] python 3.6 selenium webdriver error X display is required for sending-keys unable to ues Xvfb

查看:95
本文介绍了python 3.6 selenium webdriver错误X显示是无法发送到ues的发送键所必需的Xvfb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SeleniumWebdriver.Chrome为我的测试环境创建具有特定功能的Webdriver.

I am using selenium webdriver.Chrome to create a webdriver with specific functionality for my test environment.

    class MyDriver(webdriver.Chrome):
          def __init__(self, executable_path="chromedriver", port=0,
              chrome_options=None, service_args=None,
              desired_capabilities=None, service_log_path=None):
          super().__init__(executable_path, port, chrome_options, service_args,
                      desired_capabilities, service_log_path)  
              # vdisplay = Xvfb()
              # vdisplay.start()

测试的一部分包括发送带有element.send_keys(value)的密钥, 测试运行良好,直到几天前它开始崩溃并显示以下消息:

part of the test includes sending keys with element.send_keys(value), The tests ran fine until a few days ago it started crashing with this message:

"selenium.common.exceptions.WebDriverException:消息:未知错误:密钥代码转换需要X显示,请考虑使用Xvfb (会话信息:chrome = 59.0.3071.115) (驱动程序信息:chromedriver = 2.27.440175(9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform = Linux 4.10.0-22-generic x86_64)"

"selenium.common.exceptions.WebDriverException: Message: unknown error: an X display is required for keycode conversions, consider using Xvfb (Session info: chrome=59.0.3071.115) (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 4.10.0-22-generic x86_64)"

我一遍又一遍地搜索和研究,我不理解错误...

I searched and researched over and over I don't understand the error...

我正在使用:

  • Python 3.6
  • PyCharm
  • chromedriver linux_64bit 2.27.440175

我发现的唯一有用的链接是 chromium 在: https://bugs.chromium.org/p/chromedriver/issues/detail?id = 1772 但我不熟悉那里的工具...

The only useful link I found was a bug opened by chromium at: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1772 but I am unfamiliar with there tools...

我想知道是否有人有发送密钥或解决此错误的解决方案,我曾尝试删除chrome并将其降级...这没有帮助!

I would like to Know if anyone has a solution for sending keys or fixing this bug I have tried removing chrome and downgrading it... it did not help!

任何帮助将不胜感激!

谢谢

推荐答案

在Xvfb长期存在此问题之后,我采取了一种新方法来运行不显示的硒测试:

After a long time having this problem with Xvfb I took a new approach to run the selenium test without display:

class MySolutionsDriver(webdriver.Chrome):
    def __init__(self, executable_path=PATH_chromedriver, port=0,
             chrome_options=None, service_args=None,
             desired_capabilities=None, service_log_path=None):
        # vdisplay = Xvfb()
        # vdisplay.start()

        # for full screen uncheck two lines below and import of Options
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--start-maximized')
        chrome_options.add_argument('disable-infobars')
        chrome_options.add_argument('--disable-extensions')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_argument("--incognito")

        super().__init__(executable_path, port, chrome_options, service_args,
                     desired_capabilities, service_log_path)

使用chrome_options并通过add_argument函数添加参数,以便在不显示的情况下运行测试,我使用>"--headless".

Using chrome_options and adding arguments with the add_argument function, in order to run the tests without display I use > "--headless".

除此之外,我发现可以添加很多不错的论点!

besides that, I found lots of good arguments one can add!

希望这可以帮助任何遇到此问题的人.

Hope this can help anyone with this problem.

PS:仅供参考-Xvfb不能在Windows(或据我所知的Microsoft服务器)上运行.

PS: Just FYI- The Xvfb does not work on windows (or Microsoft servers as far as I understand).

这篇关于python 3.6 selenium webdriver错误X显示是无法发送到ues的发送键所必需的Xvfb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆