【问题标题】:How do I change the volume of Chrome using Selenium如何使用 Selenium 更改 Chrome 的音量
【发布时间】:2019-04-20 04:47:07
【问题描述】:

我正在处理一个使用 python 从 Atmel 板接收信息的项目,我需要更改 chrome 浏览器的音量。我正在尝试使用 selenium,但我只找到了如何使 Chrome 静音。

【问题讨论】:

  • Chrome 有音量设置吗?这似乎是一个系统设置。也许 chrome://settings 中有一些我不知道的特定内容?如果您能指出这一点,那么您有可能使用 Selenium 进行设置,但如果它在浏览器之外,则可能无法实现。
  • 尝试在 Selenium 中查看 ActionChains 和 Keys。如果可以通过单击键盘上的功能键来更改音量,它可能会起作用:selenium-python.readthedocs.io/…

标签: python selenium google-chrome


【解决方案1】:

你不需要硒来做到这一点。 您需要 pycaw 来控制系统上运行的应用程序的音量,这里有一个示例说明如何做到这一点。

from __future__ import print_function
from pycaw.pycaw import AudioUtilities, ISimpleAudioVolume


sessions = AudioUtilities.GetAllSessions()
for session in sessions:
    volume = session._ctl.QueryInterface(ISimpleAudioVolume)
    if session.Process and session.Process.name() == "chrome.exe":
        volume.SetMasterVolume(0.5, None)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-01
    • 2015-04-25
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多