Skip to content

Selenium Update #122

@s2t2

Description

@s2t2

Update for selenium 4.11:

import os

from dotenv import load_dotenv

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys


load_dotenv()

# default path for homebrew-installed chromedriver
CHROMEDRIVER_PATH = os.getenv("CHROMEDRIVER_PATH", default="/usr/local/bin/chromedriver")
CHROME_BINARY_PATH = os.getenv("CHROME_BINARY_PATH") # specify path where chrome binary is installed, as necessary (see "build.sh")
HEADLESS_MODE = bool(os.getenv("HEADLESS_MODE", default="false") == "true")


def create_driver(headless=HEADLESS_MODE, chromedriver_path=CHROMEDRIVER_PATH, binary_location=CHROME_BINARY_PATH):

    options = webdriver.ChromeOptions()
    # help Mac find where you installed Chrome
    # help production server find custom installation of chrome binary (see "build.sh"):
    if binary_location:
        # https://github.com/SeleniumHQ/selenium/blob/4071737de47f1cec2dfef934f3e18a2e36db20d5/py/selenium/webdriver/chromium/options.py#L34
        options.binary_location = binary_location
    if headless:
        options.add_argument('--no-sandbox')
        options.add_argument('--incognito')
        options.add_argument('--headless')
        options.add_argument('--disable-dev-shm-usage')

    #return webdriver.Chrome(chromedriver_path, options=options)

    service = Service(executable_path=chromedriver_path)
    return webdriver.Chrome(service=service, options=options)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions