请参阅下面的代码FOR CHROME:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
preferences = {"profile.default_content_setting_values.media_stream_mic": False,
"profile.default_content_setting_values.media_stream_camera": False,}
chrome_options.add_experimental_option("prefs", preferences)
driver = webdriver.Chrome(options=chrome_options)
driver.maximize_window()
driver.get("https://stackoverflow.com")
注意:
False
用于拒绝访问,True
用于允许访问
请参阅下面的代码FOR EDGE:
from selenium.webdriver.edge.options import Options
from selenium import webdriver
edge_options = Options()
preferences = {
"profile.default_content_setting_values.media_stream_mic": 2,
"profile.default_content_setting_values.media_stream_camera": 2,
}
for name, value in preferences.items():
edge_options.add_argument(f"--{name}={value}")
driver = webdriver.Edge(options=edge_options)
driver.maximize_window()
driver.get("https://stackoverflow.com")
注意:
1
用于拒绝访问,2
用于允许访问
如果您使用旧版本的 selenium (3.141.x)
EdgeOptions options = new EdgeOptions();
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
List<String> args = Arrays.asList("use-fake-ui-for-media-stream", "use-
fake-device-for-media-stream");
Map<String, Object> map = new HashMap<>();
map.put("args", args);
options.setCapability("ms:edgeOptions", map);