cant use microphone with python selenium chrome driver remoetly ( local run on my pc is ok)

268 views Asked by At

Im Automation developer, Im trying using python, chrome driver,selenium >> to allow microphone in browser.

when i run my selenium tests locally, it works ok but when i run it remotely the microphone is still disabled when i run locally, i use chrome driver, with chrome version 113 i use in chrome options "--use-fake-ui-for-media-stream" and some other options ofcourse.

and my selenium tests passed successfully, and microphone is enabled

when i run chrome remotely on selenoid server, again test run successfully, but microphone is disabled i used same options like i used locally with the "--use-fake-ui-for-media-stream" option as well

this is how i initiate the deriver remotely:
    webdriver.Remote(
                desired_capabilities=capabilities,
                command_executor=SelenoidServer.selenoid_server_path,
                options=chrome_options,
the desired cap in remote are:
        "browserName": "chrome",
        "browserVersion": "latest-stable",
        "selenoid:options": {"enableVNC": True, "enableVideo": True},

The options for local and remotely are:
        "--ignore-certificate-errors",
        # "--incognito",
        "--no-sandbox",
        "--no-default-browser-check",
        "--disable-gpu",
        "--disable-extensions",
        "--disable-default-apps",
        "--disable-web-security",
        "--disable-infobars",
        "--disable-dev-shm-usage",
        "--disable-translate",
        "--disable-webgl",
        "--start-maximized",
        "--use-fake-ui-for-media-stream",

experimenral options:
        "profile.default_content_setting_values.media_stream_mic": 2,
        "profile.default_content_setting_values.media_stream_camera": 2,
        "profile.default_content_setting_values.geolocation": 2,
        "profile.default_content_setting_values.notifications": 2,
        "profile.default_content_settings.popups": 2,
        "plugins.plugins_disabled": "Chrome PDF Viewer, Adobe Flash Player",
        "credentials_enable_service": "false",
        "profile.password_manager_enabled": "false",
        "download.prompt_for_download": "false",
        "enableNetwork": "true",
        "download.default_directory": str(TEMP_FOLDER_PATH),

this is how i run it locally:
        Chrome(service=Service(ChromeDriverUtil.chromedriver_path), 
  options=chrome_options)

in snapshot on right side you can see the browser in local run, that we have no warnning on the mic button, while on the left side when we run remotly we can see the warning on the button enter image description here can anyone help with this ?

1

There are 1 answers

0
user18672350 On

try this with your user data path

options.add_argument(r'--user-data-dir=C:\Users\smart\AppData\Local\Google\Chrome\User Data\Default.')

or this

options.add_experimental_option("prefs", {
    "profile.default_content_setting_values.media_stream_mic": 1
})

and this

driver.execute_cdp_cmd(
    "Browser.grantPermissions",
    {
        "origin": TARGET_URL,  # e.g https://www.google.com
        "permissions": ["geolocation", "audioCapture", "displayCapture", "videoCapture",
                        "videoCapturePanTiltZoom"]
    },
)

also you could try with older versions of selenium-chromedriver-chrome browser, using executable path and binary path

Hope it's somehow useful