Selenium: "TypeError: Object of type 'set' is not JSON serializable" error observed when passing a dictionary to ChromeOptions object in Python 3.6.1

Created on 6 Oct 2017  路  2Comments  路  Source: SeleniumHQ/selenium

Meta - TypeError: Object of type 'set' is not JSON serializable error observed when passing a dictionary toChromeOptions object and invoke webdriver.Chrome() in Python 3.6.1

OS: Windows 8 Pro
Selenium Version: 3.6.0
Browser: Google Chrome
Browser Version: 61.0.3163.100 (Official Build) (64-bit)
ChromeDriver: v2.32.498550

Expected Behavior - webdriver.Chrome() should accept dictionary object passed through ChromeOptions object.

Actual Behavior - webdriver.Chrome() doesn't accepts dictionary object passed through ChromeOptions object and shows TypeError: Object of type 'set' is not JSON serializable error.

Steps to reproduce -

Minimal Code Block:

from selenium import webdriver

chrome_opt = webdriver.ChromeOptions()
prefs = {"credentials_enable_service", False}
prefs = {"profile.password_manager_enabled", False}
chrome_opt.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=chrome_opt, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("https://google.com")

Console Output (Error Stack Trace):

Traceback (most recent call last):
  File "C:\Users\AtechM_03\LearnAutmation\PythonProject\Stackoverflow\passwordManagerChrome.py", line 7, in <module>
    driver = webdriver.Chrome(chrome_options=chrome_opt, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
  File "C:\Python\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 151, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 240, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 306, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 461, in execute
    data = utils.dump_json(params)
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\utils.py", line 34, in dump_json
    return json.dumps(json_struct)
  File "C:\Python\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "C:\Python\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Python\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "C:\Python\lib\json\encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'set' is not JSON serializable
C-py

Most helpful comment

You are using it wrong. Instead of:

prefs = {"credentials_enable_service", False}

which is a set, you need to use dictionary:

prefs = {"credentials_enable_service": False}

All 2 comments

You are using it wrong. Instead of:

prefs = {"credentials_enable_service", False}

which is a set, you need to use dictionary:

prefs = {"credentials_enable_service": False}

Thanks a lot for the quick help Alex. @p0deje

Was this page helpful?
0 / 5 - 0 ratings