如果页面在循环 1 后自动刷新并且不想在 Selenium 中继续循环 2,如何循环

How to loop if the page automatically refresh after loop 1 and don't want to continue loop 2 in Selenium

请教我如何循环tr[1]、[2]、[3]或N个数字,按照网站上提供的table如果循环1后页面自动刷新,不要不想继续循环 2、循环 3、循环 N?

so like this for example: loop 1 (page auto refresh) > loop 2 (page auto refresh) > loop N (page auto refresh) | *This auto refresh page is directly from the website, not from the code

代码:

try:
    while True:
        browser.get('URL')
        options = browser.find_elements_by_xpath('//*[@id="event"]/tbody/tr')
        for opt in options:
            opt.find_element_by_xpath('./td[9]').click()
            time.sleep(2.5)
            break
except (ElementNotVisibleException, WebDriverException, NoSuchElementException):
        pass

这里有一个循环while用于当for循环到达网站上的循环N时不断迭代 我建议循环有错误,但我不知道它在哪里,所以我可以继续循环

假设在对 td 标签执行 click 操作后页面刷新,对于下一次迭代,不再找到元素 options(因为页面已刷新)。

尝试在每次迭代中找到元素 options,以便即使在页面刷新后也能找到该元素。

try:
    while True:
        browser.get('URL')
        options = browser.find_elements_by_xpath('//*[@id="event"]/tbody/tr')
        for i in range(len(options)):
            options = browser.find_elements_by_xpath('//*[@id="event"]/tbody/tr')
            options[i].find_element_by_xpath('./td[9]').click()
            time.sleep(2.5)
            break
except (ElementNotVisibleException, WebDriverException, NoSuchElementException):
        pass