I wrote a test that parses links from a web page, and in a loop, clicks on each of them, and then returns to the main page. But, each iteration is accompanied by parsing the entire web page again and again and overwriting the links array, although only one link is needed per iteration. I understand that this is inefficient. How can I optimize this?
I tried parsing the links only once and then iterating through them in a loop. After the first iteration, it goes back (to the main page) and tries to click on the second link, but it's not interactive (I think it's because of the web elements that are stored in the links array changing every time you go to the page).
def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://yandex.ru') def test_01(self): driver = self.driver links =  time.sleep(3) links = driver.find_elements_by_css_selector("a") for i in range(len(links)): links = driver.find_elements_by_css_selector("a") links[i].click() driver.get('https://yandex.ru') time.sleep(3)