Why doesn't Selenium ActionChains work in a loop?

17 Views Asked by At

When i use ActionChains in a loop it only clicks on the first element after that i get an error 'StaleElementReferenceException: Message: stale element reference: stale element not found'

My code:

for car in  cars:
    counter += 1
    ActionChains(driver).scroll_to_element(car).perform()
    car.find_element(By.TAG_NAME, 'td').find_element(By.TAG_NAME, 'a').click()
    driver.get(url_cars)
    time.sleep(5)

I checked selenium error documentation but i couldn't find a solution

SOLUTION

I was able to solve the problem by opening the link in a new tab in every time. But i'd like to know why the source code doesn't work

0

There are 0 best solutions below