How to allow or deny notification of microphone and camera popup in Firefox using Selenium WebDriver with Java

旧城冷巷雨未停 提交于 2020-06-12 06:02:16

问题


I am not able to click on the Allow button of access camera authentication popup in Firefox browser using Selenium WebDriver with Java.

Below is the code which is using:

Map<String, Object> prefs = new HashMap<String, Object>();
WebDriverManager.firefoxdriver().setup();
prefs.put("profile.default_content_setting_values.media_stream_mic", 1);
prefs.put("profile.default_content_setting_values.media_stream_camera", 1);
prefs.put("profile.default_content_setting_values.notifications", 1);        
prefs.put("credentials_enable_service", false); 
prefs.put("profile.password_manager_enabled", false);


FirefoxOptions options = new FirefoxOptions();
options.addPreference("dom.webnotifications.enabled", false);
options.addArguments("--disable-infobars");
options.addArguments("use-fake-ui-for-media-stream");
options.addArguments("start-maximized");
options.addArguments("--disable-extensions");
driver = new FirefoxDriver(options);

Here is the look of popup:


回答1:


You can use the following preferences (in this case to allow):

...
options.addPreference("permissions.default.microphone", 1);
options.addPreference("permissions.default.camera", 1);
...

Hope it helps you!




回答2:


I am using these options to my firefox driver, it's perfectly working

public static FirefoxOptions setFireFoxOptions() {
    FirefoxOptions options = new FirefoxOptions();
    options.addPreference("media.navigator.permission.disabled", true);
    return options;
}


来源:https://stackoverflow.com/questions/54002953/how-to-allow-or-deny-notification-of-microphone-and-camera-popup-in-firefox-usin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!