【问题标题】:Fake webcam chrome option when used with python selenium webdriver与 python selenium webdriver 一起使用时的假网络摄像头 chrome 选项
【发布时间】:2022-01-18 09:18:42
【问题描述】:

当启动 chrome per python selenium webdriver script 时,我没有获得 特定 chrome 选项以正常工作。

目标是在 python selenium 脚本中使用假网络摄像头启动 chrome,该摄像头播放视频文件。

有问题的选项是“use-file-for-fake-video-capture”结合“use-fake-device-for-media-stream”:

options.add_argument("--use-fake-device-for-media-stream")
options.add_argument("--use-file-for-fake-video-capture=C:\Testfiles\videofiles\bus_cif.y4m")

在带有 chrome.exe 的批处理文件中使用这两个选项都可以正常工作。例如,以下批次工作 fine 并使用了伪造的网络摄像头视频文件: "C:\Program Files\Google\Chrome\Application\chrome.exe" --use-fake-device-for-media-stream --use-file-for-fake-video-capture=C:\Testfiles\videofiles\bus_cif.y4

另外,我的 python chrome webdriver 脚本选项的其余部分工作正常,所以代码本身应该是正确的。例如,以下选项工作很好

options.add_argument("--allow-file-access-from-files")
options.add_argument("--use-fake-ui-for-media-stream")
options.add_argument("--disable-infobars")

Chrome 97.x(带有最新稳定的 chromium webdriver 文件)

在带有选项的 python 脚本中使用“use-file-for-fake-video-capture”选项有什么特别之处吗?或者路径必须是另一种格式?

非常感谢!

【问题讨论】:

    标签: python selenium google-chrome selenium-webdriver selenium-chromedriver


    【解决方案1】:

    想通了。昨天花了几个小时,但今天在发布到 stackoverflow 后不久,我自己找到了解决方案:

    问题是我使用的路径: Windows path in Python

    使用以下内容时,一切正常,即使通过 python 脚本启动 chrome,也会使用假视频:

    options = Options()    
    options.add_argument("--use-fake-ui-for-media-stream")
    options.add_argument("--use-fake-device-for-media-stream")
    options.add_argument(r'--use-file-for-fake-video-capture=C:\Testfiles\videofiles\bus_cif.y4m')
    self.driver = webdriver.Chrome(options=options)
    

    在使用带有反斜杠的 Windows 路径时,重要的是 r'。我认为另一种解决方案是使用斜杠而不是反斜杠。

    【讨论】:

      猜你喜欢
      • 2012-12-05
      • 2016-07-14
      • 1970-01-01
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多