3

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

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
  • tried this [https://stackoverflow.com/questions/6183276/how-do-i-run-selenium-in-xvfb] with [https://stackoverflow.com/users/16148/corey-goldberg]s answer but did not help! – Moshe Slavin Jul 09 '17 at 11:16
  • Ever find a solution? –  Aug 08 '17 at 21:56
  • 1
    No i haven't... I just removed my chrome-driver and downloaded a new one... must of the time it works... this project is run on Jenkins so i just add the Xvfb for it to run with no display – Moshe Slavin Aug 09 '17 at 08:19
  • @traw1234 I have posted an answer hope it helps you... – Moshe Slavin Aug 22 '18 at 11:28
  • @GhostCat I am glad you made the effort to contact me, thanks! regarding the review, I should have added a comment to add some of his code... and not just 'Requires Editing'? I'm new at reviewing... thanks again! – Moshe Slavin Nov 04 '18 at 13:51
  • 1
    "Requires edit" means: **anybody** can fix the question by improving formatting, and fixing minor glitches. But whenever the OP asking the question needs to add more information, then you should look for a valid close reason. Only vote edit if you think "**I** could fix this question by editing, I just dont have the time right now". I hope that makes sense. Beyond that: I appreciate the quick and kind comeback! But sure: giving a comment to the OP telling him whats wrong would often be helpful ... – GhostCat Nov 04 '18 at 13:55

1 Answers1

0

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

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38