Operating on this website: https://www.livetulokset.com/
my_leagues = browser.find_element_by_id('my-leagues-list') # single element
leagues = my_leagues.find_elements_by_tag_name('li') # list of elements
for i in leagues:
i.click() # Click first league
sleep(1) # sleep second to be able to see the click in monitor
browser.find_element_by_css_selector('a.menuTop__item:nth-child(1) > div:nth-child(2)').click() # click football icon
Code clicks first league from the list, then clicks the football icon to get back to main page. When trying to click the second league from the list, StaleElementReferenceException occurs due the page refresh. How could this be prevented?
Edit:
I really need solution for not to lose the web element during for loop. This football website is just for you guys to test my problem in action.