Python Selenium无头浏览器中--mute-audio参数是否生效?
无头模式下Selenium Firefox的--mute-audio参数是否生效?
结论:在Firefox无头模式下,
--mute-audio这个命令行参数通常不生效。Firefox的无头模式对音频相关的命令行参数支持不完善,即使添加该参数,无头实例也不会处理它,无法实现静音效果。替代方案:改用Firefox的偏好设置来实现静音,这个方式在无头模式下更可靠。通过设置
media.volume_scale为0.0,可以直接将所有媒体音量设为0,达到静音目的。
修改后的函数代码如下:
def start_driver(self): firefox_options = web.FirefoxOptions() firefox_options.add_argument('--headless') # 用偏好设置替代--mute-audio,实现无头模式下稳定静音 firefox_options.set_preference("media.volume_scale", "0.0") os.environ["webdriver.gecko.driver"] = gecko_driver_path self.driver = web.Firefox(options=firefox_options)
内容的提问来源于stack exchange,提问作者Will C
相关产品推荐
相关产品推荐

