python 3.6 selenium webdriver error X display is required for sending-keys unable to ues Xvfb

Viewed 569

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()

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: 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...

I'm using:

  • Python 3.6
  • Selenium
  • PyCharm
  • chromedriver linux_64bit 2.27.440175

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...

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!

Any help would be appreciated!

Thanks

1 Answers

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)

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: Just FYI- The Xvfb does not work on windows (or Microsoft servers as far as I understand).

Related