Accept permission request in chrome using selenium Accept permission request in chrome using selenium google-chrome google-chrome

Accept permission request in chrome using selenium


Wrestled with this quite a bit myself.

The easiest way to do this is to avoid getting the permission prompt is to add --use-fake-ui-for-media-stream to your browser switches.

Here's some shamelessly modified code from @ExperimentsWithCode's answer:

from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_options = Options()chrome_options.add_argument("--use-fake-ui-for-media-stream")driver = webdriver.Chrome(executable_path="path/to/chromedriver", chrome_options=chrome_options)


@ExperimentsWithCode

Thank you for your answer again, I have spent almost the whole day today trying to figure out how to do this and I've also tried your suggestion where you add that flag --disable-user-media-security to chrome, unfortunately it didn't work for me.

However I thought of a really simple solution:

To automatically click on Allow all I have to do is press TAB key three times and then press enter. And so I have written the program to do that automatically and it WORKS !!!

The first TAB pressed when my html page opens directs me to my input box, the second to the address bar and the third on the ALLOW button, then the Enter button is pressed.

The python program uses selenium as well as PyWin32 bindings.


Thank you for taking your time and trying to help me it is much appreciated.


So I just ran into another question asking about disabling a different prompt box. It seems there may be a way for you to accomplish your goal.

This page lists options for starting chrome. One of the options is

--disable-user-media-security

"Disables some security measures when accessing user media devices like webcams and microphones, especially on non-HTTPS pages"

So maybe this will work for you:

from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_options = Options()chrome_options.add_argument("--disable-user-media-security=true")driver = webdriver.Chrome(executable_path="path/to/chromedriver", chrome_options=chrome_options)