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)
Example code
The following is an example code that reproduce the error
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
domain = "https://www.lazyvim.org/"
driver = webdriver.Chrome(webdriver.ChromeOptions())
driver.maximize_window()
driver.get(domain)
# sleep to view result for debugging purpose. not required
time.sleep(3)
# i know implicit wait are bad. just for demo code
driver.implicitly_wait(3)
# find the sidebar on left
sidebar_selector = (By.CSS_SELECTOR, "div.sidebar_njMd")
sidebar = driver.find_element(*sidebar_selector)
# find the > button next to configuration side menu to expand content
config_dropdown_button_selector = locate_with(
By.CSS_SELECTOR, "button.clean-btn.menu__caret"
).straight_right_of({By.CSS_SELECTOR: 'a[href="configuration"]'})
config_dropdown_button = sidebar.find_element(config_dropdown_button_selector)
# click the > button
config_dropdown_button.click()
# sleep to view the result
time.sleep(4)
driver.quit()
and I get
DevTools listening on ws://127.0.0.1:65184/devtools/browser/da53e6c1-eff4-42fc-bfe8-ff1a6c16902a
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1754809316.366736 18344 voice_transcription.cc:58] Registering VoiceTranscriptionCapability
[28756:25756:0810/150156.584:ERROR:google_apis\gcm\engine\registration_request.cc:291] Registration response error message: DEPRECATED_ENDPOINT
Traceback (most recent call last):
File "C:\Users\bd080\test_project\issue_demo2.py", line 27, in <module>
config_dropdown_button = sidebar.find_element(config_dropdown_button_selector)
File "C:\Users\bd080\test_project\venv\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 603, in find_element
return self._execute(Command.FIND_CHILD_ELEMENT, {"using": by, "value": value})["value"]
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bd080\test_project\venv\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 574, in _execute
return self._parent.execute(command, params)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "C:\Users\bd080\test_project\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 445, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\bd080\test_project\venv\Lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 400, in execute
data = utils.dump_json(params)
File "C:\Users\bd080\test_project\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

.below(myRelativeLocator)- and this can mean problem is in different place, and you probably use wrong valuesdriverinstead ofsidebarthen this problem disappears (but result may not be the same). In documentation I don't see any information about this problem but all examples usedriver. Maybe it is bug and it needs to send this problem to author(s). At least you can check if someone already send issue for this.