简体   繁体   中英

How to disable camera and microphone popup alert via Selenium WebDriver tests?

Currently, I have tests which perform a specific test flow however this specific flow causes Chrome to present the user (Tests) with a microphone, camera alert popups:

在此处输入图片说明

I need a way to disable the alerts via Selenium Webdriver / Java, I have attempted to use Chrome options, with no luck; example code:

ChromeOptions op = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
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.geolocation", 1);
prefs.put("profile.default_content_setting_values.notifications", 1);
op.setExperimentalOption("prefs", prefs);
RemoteWebDriver remoteDriver = new RemoteWebDriver(new URL(REMOTE_HUB_URL), op);

Even solely tried the following with no luck:

prefs.put("profile.default_content_settings.popups", 1);

You need to use the "2" value for that. Code:

...
prefs.put("profile.default_content_setting_values.media_stream_mic", 2);
prefs.put("profile.default_content_setting_values.media_stream_camera", 2);
...

PS: The value "1" is used for allowing the option, "2" -- for blocking.

I hope it helps you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM