Accept permission request in chrome using selenium

I have an HTML / Javascript file with google web speech api and I do selenium testing, however every time I enter the site, the browser asks for permission to use my microphone and I need to click "ALLOW".

How to make selenium by clicking on ALLOW automatically?

+4
source share
6 answers

@ExperimentsWithCode

Thanks for your reply again. Today I spent almost the whole day trying to figure out how to do this, and I also tried your suggestion when you add this flag --disable-user-media-securityto chrome, unfortunately, it does not work for me.

:

" , ", TAB , . , , !!!

TAB, , html, , - , - ALLOW, Enter.

python , PyWin32.


, , .

+7

.

- , add --use-fake-ui-for-media-stream .

- @ExperimentsWithCode :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--use-fake-ui-for-media-stream")

driver = webdriver.Chrome(executable_path="path/to/chromedriver", chrome_options=chrome_options)
+6

, . , .

. :

--disable-user-media-security

" , - , , HTTPS"

, , :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--disable-user-media-security=true")

driver = webdriver.Chrome(executable_path="path/to/chromedriver", chrome_options=chrome_options)
+2

[Java]: , , Robot-java.awt

public void allowGEOLocationCapture(){
    Robot robot = null;
    try {
        robot = new Robot();
        robot.keyPress(KeyEvent.VK_TAB);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.delay(600);
    } catch (AWTException e) {
       getLogger().info(e);
    }
 }
0

add_experimental_option, .

from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option('prefs',{'profile.default_content_setting_values.notifications':1})
driver = webdriver.Chrome(chrome_options=chrome_options)
0

JAVA! . .

:

    // opening new window
    Robot robot;
    try {
        robot = new Robot();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.delay(100);
        robot.keyPress(KeyEvent.VK_N);
        robot.delay(100);
        robot.keyRelease(KeyEvent.VK_N);
        robot.delay(100);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.delay(100);
    } catch (AWTException e) {
        log.error("Failed to press buttons: " + e.getMessage());
    }
0

Source: https://habr.com/ru/post/1525791/


All Articles