如何保存麦克风请求设置?

How to save microphone request settings?

我正在尝试自动化一个在我的测试中运行良好的消息站点,但现在浏览器一直要求我阻止或允许麦克风。解决办法是什么?我请求你的帮助!

注意:根据我的代码,它开始通过麦克风捕获音频,但我不想录制音频,但我必须接受此站点的麦克风。

这是我在 python

中为此自动化创建的 __init__
 def __init__(self):
     #init declara o driver para ser acessado no self, acessar o programa todo
     chrome_options = Options()
     #caminho do chromium
     try:
         chrome_options.binary_location = dir_absolutle + '\chrome-win' + '\chrome.exe'
     except:
         chrome_options.binary_location = os.getcwd() + '\chrome-win' + '\chrome.exe'
     #chrome_options.add_argument("--headless")  
     #chrome_options.add_argument("--disable-infobars")
     #chrome_options.add_argument("--disable-extensions")
     #chrome_options.add_argument("disable-media-stream")
     #chrome_options.add_argument("allow-file-access-from-files")
     #usar som ou video falso
     #chrome_options.add_argument("use-fake-device-for-media-stream")
     #chrome_options.add_argument("use-fake-ui-for-media-stream")
        # Pass the argument 1 to allow and 2 to block
     chrome_options.add_experimental_option("prefs",{\
         "profile.default_content_setting_values.media_stream_mic" : 2})
     chrome_options.add_argument('--ignore-certificate-errors-spki-list')
     #chrome_options.add_argument("--unlimited-storage")
     chrome_options.add_argument('--ignore-certificate-errors')
     chrome_options.add_argument('--ignore-ssl-errors')
     chrome_options.add_argument('--lang=pt-BR')
     chrome_options.add_argument('--disable-notifications')
     chrome_options.add_argument('--disable-gpu')
     #chrome_options.add_experimental_option("excludeSwitches", ["disable-popup-blocking"])
     args = ["hide_console", ] 
     #caps = webdriver.DesiredCapabilities.CHROME.copy() 
     #caps['acceptInsecureCerts'] = True
     try:
         caminho_chromedriver = dir_absolutle + '\chromedriver.exe'
     except:
         caminho_chromedriver = os.getcwd() + '\chromedriver.exe'
     #caminho_chromedriver = r'C:\Users\Daniel pc\Desktop\whatsappcdb\chromedriver.exe'
     self.driver = webdriver.Chrome(executable_path=caminho_chromedriver,options=chrome_options, service_args=args)
     self.wait = WebDriverWait( #aqui a variavel self.wait está recebendo o webdriverwait com as caracteristicas
     driver=self.driver,
     timeout= 10,
     poll_frequency=6
      )
 pass

如果我取消选中

#chrome_options.add_argument("use-fake-device-for-media-stream")
#chrome_options.add_argument("use-fake-ui-for-media-stream")

它将开始录制音频,我不想让它开始录制。如何不初始化此录音?

谢谢

您可以使用 pickle

从网站保存 cookie
import pickle
import selenium.webdriver

driver = selenium.webdriver.Firefox()
driver.get("http://www.google.com")
pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))

将它们加回来是

import pickle
import selenium.webdriver

driver = selenium.webdriver.Firefox()
driver.get("http://www.google.com")
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
    driver.add_cookie(cookie)