【问题标题】:remove arguments passed to chrome by selenium / chromedriver删除 selenium / chromedriver 传递给 chrome 的参数
【发布时间】:2013-05-13 19:17:28
【问题描述】:

我将 selenium 与 python 和 chromium / chromedriver 一起使用。我想删除传递给 chrome 的开关(例如 --full-memory-crash-report),但到目前为止我只能找到如何添加更多开关。

我目前的设置:

from selenium import webdriver
driver = webdriver.Chrome(executable_path="/path/to/chromedriver")
driver.get(someurl)

据我了解,这可用于添加参数:

from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--some-switch")
driver = webdriver.Chrome(chrome_options=chrome_options)

那么,我如何摆脱默认参数或清除所有默认参数并仅传递自定义列表?

【问题讨论】:

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


    【解决方案1】:

    在 C# 中:

    ChromeOptions options = new ChromeOptions();
    options.AddExcludedArgument("test-type"); // To remove arg "--test-type=webdriver"
    

    【讨论】:

      【解决方案2】:

      它帮助了我:

      options = webdriver.ChromeOptions()
      options.add_experimental_option("excludeSwitches", ["test-type"])
      options.add_argument("--incognito")
      driver = webdriver.Chrome(options=options)
      

      在这里找到解决方案https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification

      【讨论】:

        【解决方案3】:

        使用 excludeSwitches 镀铬选项。见:https://sites.google.com/a/chromium.org/chromedriver/capabilities

        【讨论】:

          【解决方案4】:

          使用chrome_options.arguments.remove("--some-switch") 删除单个选项。要将其擦拭干净,请使用chrome_options.arguments[:] = []

          您可以检查 chrome_options 对象的属性:

          from pprint import pprint
          pprint (vars(chrome_options))
          

          【讨论】:

          • 这对我不起作用。参数已经为空。我可以删除/禁用 chromedriver 设置的开关。
          猜你喜欢
          • 2022-01-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多