Accept permission request in chrome using selenium

后端 未结 8 1793
旧巷少年郎
旧巷少年郎 2020-12-10 06:37

I have a HTML/Javascript file with google\'s web speech api and I\'m doing testing using selenium, however everytime I enter the site the browser requests permission to use

相关标签:
8条回答
  • 2020-12-10 06:45

    You can allow using add_experimental_option as shown below.

    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 讨论(0)
  • 2020-12-10 06:53

    Beware of Mohana Latha's answer for JAVA! The code is only pressing the buttons and NEVER releasing them. This will bring bunch of issues later on.

    Use this instead:

        // 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 讨论(0)
  • 2020-12-10 06:59

    [Java]: Yes there is a simple technique to click on Allow button using 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 讨论(0)
  • 2020-12-10 07:04

    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 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)
    
    0 讨论(0)
  • 2020-12-10 07:05

    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 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)
    
    0 讨论(0)
  • 2020-12-10 07:05

    Do it For android chrome it really work!

    adb -s emulator-5554 push <YOU_COMPUTER_PATH_FOLDER>/com.android.chrome_preferences.xml  /data/data/com.android.chrome/shared_prefs/com.android.chrome_preferences.xml
    

    File config here https://yadi.sk/d/ubAxmWsN5RQ3HA Chrome 80 x86

    or you can save the settings file after ticking the box with your hands, in adb its "pull" - command

    0 讨论(0)
提交回复
热议问题