Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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']

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

but same error I received

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading