TypeError: Object of type RelativeBy is not JSON serializable error using relative_locator through Selenium Python

Question:

I’m trying to write my own flight tracker using selenium and chrome driver. In order to get to the input box, I’m trying to travel down the tree of embedded html elements (for some reason I can’t get straight to it, even using the xpath attribute in webdriver).

I tried the solution from this thread but it did not work (currently using a newer version of selenium, so this solution might be outdated)

Here is my code:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with

driver_service = Service(executable_path = '/path/chromedriver')
url = 'https://www.google.com/travel/flights'
browser = webdriver.Chrome(service = driver_service)
browser.get(url)
bigBody = browser.find_element(By.ID,'yDmH0d')
#WebElement data type
wrongWiz = bigBody.find_element(By.ID, 'ow4')
wizLoc = locate_with(By.TAG_NAME, 'c-wiz').below(wrongWiz)
bigWiz = bigBody.find_elements(wizLoc) 
##This part is what throws the error, whether I'm using element or elements. 

Here’s the error:

TypeError: Object of type RelativeBy is not JSON serializable
Asked By: Fox

||

Answers:

This part of the code:

locate_with(By.TAG_NAME, 'c-wiz')

though a legitimate Relative Locators based expression, but still you have to pass it as an argument to browser.find_element() as follows:

wizLoc = driver.find_element(locate_with(By.TAG_NAME, 'c-wiz').below(wrongWiz))
Answered By: undetected Selenium