InvalidArgumentException: Message: invalid argument: invalid locator error coming

I was doing a project related to flight price when I truing to web scrape dept time I got the error . url is https://flight.yatra.com/air-search-ui/dom2/trigger?ADT=1&CHD=0&INF=0&class=Economy&destination=BOM&destinationCountry=IN&flexi=0&flight_depart_date=22%2F01%2F2022&hb=0&noOfSegments=1&origin=DEL&originCountry=IN&type=O&unique=254010891105&viewName=normal

my code was:

dept_time=driver.find_elements("//div[@class='i-b col-4 no-wrap text-right dtime col-3']")
dept= []
for i in dept_time:
    a = i.get_attribute('innerText')
    print(a)
    dept.append(a)
print(dept)

I also tried "//div[@class='i-b pr']

but same error I received


Solution 1:

Instead of

dept_time=driver.find_elements("//div[@class='i-b col-4 no-wrap text-right dtime col-3']")

Try

dept_time=driver.find_elements_by_xpath("//div[@class='i-b col-4 no-wrap text-right dtime col-3']")

Or

dept_time=driver.find_elements(By.XPATH, "//div[@class='i-b col-4 no-wrap text-right dtime col-3']")

Also, don't forget about wait / delay to use with your code to let the elements loaded before you are reading their inner texts.