Skip to content Skip to sidebar Skip to footer

Selenium Chromedriver Exception When Enumerating Elements By Xpath

I'm trying to convert a Selenium script from Firefox to Chrome. The code works as expected with Firefox and geckodriver on x86_64. geckodriver does not support ARM well so I am att

Solution 1:

The problem seems to be, the name of the Chrome browser is a moving target on different OSes and platforms. This code has avoided the exception on x86_64 and ARM on Linux:

defget_chrome():
    """
    Helper function to locate chrome browser.
    """if os.path.isfile('/usr/bin/chromium-browser'):
        return'/usr/bin/chromium-browser'if os.path.isfile('/usr/bin/chromium'):
        return'/usr/bin/chromium'if os.path.isfile('/usr/bin/chrome'):
        return'/usr/bin/chrome'if os.path.isfile('/usr/bin/google-chrome'):
        return'/usr/bin/google-chrome'returnNone

And then use it like:

if version.parse(selenium.__version__) >= version.parse("3.0"):
    opts = Options()
    opts.binary_location = get_chrome()
    opts.add_argument('--headless')
    opts.add_argument('--no-sandbox')
    opts.add_argument('--disable-dev-shm-usage')

    driver = webdriver.Chrome(chrome_options=opts)
    driver.maximize_window()
else:
    profile = webdriver.ChromeProfile()
    profile.headless = True
    profile.binary_location = get_chrome()

    driver = webdriver.Chrome(profile)
    driver.maximize_window()

Post a Comment for "Selenium Chromedriver Exception When Enumerating Elements By Xpath"