如何在Chrome中允许对内容进行权限 [英] How to allow permissions to content in Chrome

查看:1563
本文介绍了如何在Chrome中允许对内容进行权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入困境,无法在WebDriver中使用相机和麦克风:



我如何通过WebDriver处理这个问题?我没有在互联网上找到任何与此相关的有用信息。



预先致谢。



PS: 如何关闭Python / Selenium中的麦克风/摄像头弹出窗口? - 不解决我的问题(我不需要假)。

解决方案

/通过首选项阻止不同的内容:

  from selenium import webdriver 
options = webdriver.ChromeOptions()
options.add_argument( - disable-infobars)
options.add_argument( - window-size = 800,600)

options.add_experimental_option(prefs,{ \\
profile.default_content_setting_values.media_stream_mic:1,#1:allow,2:block
profile.default_content_setting_values.media_stream_camera:1,#1:allow,2:block
profile.default_content_setting_values.geolocation:1,#1:允许, 2:block
profile.default_content_setting_values.notifications:1#1:allow,2:block
})

driver = webdriver.Chrome(chrome_options = options)


I am in stuck and cannot allow using camera and microphone in WebDriver:

How can I handle this by WebDriver? I did not find any helpful info on the Internet related to this.

Thanks in advance.

PS: How can I close the microphone/camera popup in Python / Selenium? -- is not solving my case (I don't need "fake").

解决方案

You can allow/block the different contents though the preferences:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--disable-infobars")
options.add_argument("--window-size=800,600")

options.add_experimental_option("prefs", { \
    "profile.default_content_setting_values.media_stream_mic": 1,     # 1:allow, 2:block 
    "profile.default_content_setting_values.media_stream_camera": 1,  # 1:allow, 2:block 
    "profile.default_content_setting_values.geolocation": 1,          # 1:allow, 2:block 
    "profile.default_content_setting_values.notifications": 1         # 1:allow, 2:block 
  })

driver = webdriver.Chrome(chrome_options=options)

这篇关于如何在Chrome中允许对内容进行权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆