[Python] TypeError: Object of type RelativeBy is not JSON serializable for find_elements of...

Discussão em 'Python' iniciado por Stack, Agosto 9, 2025.

  1. Stack

    Stack Membro Participativo

    Why am I getting the error below when the method signature of find_elements apparently does support RelativeBy? I bypassed this error by not using relativeBy. Using selenium 4.33.0 and python 3.13.6


    inner_elements = element.find_elements(by, value)
    File "\venv\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 632, in find_elements
    return self._execute(Command.FIND_CHILD_ELEMENTS, {"using": by, "value": value})["value"]
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "\venv\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 574, in _execute
    return self._parent.execute(command, params)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
    File "\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 445, in execute
    response = self.command_executor.execute(driver_command, params)
    File "\venv\Lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 400, in execute
    data = utils.dump_json(params)
    File "\venv\Lib\site-packages\selenium\webdriver\remote\utils.py", line 23, in dump_json
    return json.dumps(json_struct)
    ~~~~~~~~~~^^^^^^^^^^^^^
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1776.0_x64__qbz5n2kfra8p0\Lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1776.0_x64__qbz5n2kfra8p0\Lib\json\encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1776.0_x64__qbz5n2kfra8p0\Lib\json\encoder.py", line 261, in iterencode
    return _iterencode(o, 0)
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1776.0_x64__qbz5n2kfra8p0\Lib\json\encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
    f'is not JSON serializable')
    TypeError: Object of type RelativeBy is not JSON serializable




    I was using a relativeBy value to find an element inside a specific element. so the code was

    myRelativeLocator = locate_with(By.CSS_SELECTOR, "div.someclass").below({By.CSS_SELECTOR:"h4.some_label"})
    myWebsitePopupWindow.find_elements(myRelativeLocator)

    Continue reading...

Compartilhe esta Página