My code
for idx, row in tqdm(df.iterrows(), total=df.shape[0]):
imgs = []
try:
driver.get(row['listing_url'])
sleep(10)
script = "document.getElementsByClassName('accordion-toggle')[0].click();"
driver.execute_script(script)
sleep(10)
scroll_down(driver)
imgs = driver.find_elements(By.XPATH, '//img[@class="i1o0kbi8 i1mla2as i1cqnm0r dir dir-ltr"]')
imgs = list(set([img.get_attribute('src') for img in imgs]))
finally:
os.makedirs('images', exist_ok=True)
with open(f'images/{row["id"]}_{row["host_id"]}.json', 'w') as f:
json.dump(imgs, f)
Error
JavascriptException: Message: javascript error: Cannot read properties of undefined (reading 'click')
What is wrong with my code and what is the correct approach