我想在我的 selenium chromedriver 项目中使用 2 个实验选项,但我没有获得有关“add_experimental_option”函数的足够信息,我想使用 2 个实验选项“prefs”和“debuggerAddress”,当我尝试运行它时,报错,只能用一个,怎么两个都用?
opt = Options()
opt.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
opt.add_experimental_option("prefs", { \
"profile.managed_default_content_settings.images": 2
})
错误信息
Traceback (most recent call last):
File "exampleselenium.py", line 28, in <module>
driver = webdriver.Chrome(executable_path="chromedriver.exe",options=opt,service_log_path='NUL')
File "C:\Users\Faraaz\anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Faraaz\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Faraaz\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Faraaz\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Faraaz\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: prefs