【发布时间】:2019-04-27 04:53:34
【问题描述】:
我的程序抛出错误消息“过时的元素引用:元素未附加到页面文档”。翻看之前的帖子(如Python Selenium stale element fix),发现调用click函数后并没有更新url。我更新了网址。但是,它并没有解决问题。谁能指出我在哪里犯错了?这是我的代码:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-infobars")
driver = webdriver.Chrome(chrome_options=chrome_options,executable_path="path of driver here")
driver.get("https://stackoverflow.com/users/37181/alex-gaynor?tab=topactivity")
if driver.find_elements_by_xpath("//a[@class='grid--cell fc-white js-notice-close']"):
driver.find_element_by_xpath("//a[@class='grid--cell fc-white js-notice-close']").click()
inner_tabs = driver.find_elements_by_xpath("//div[@class='tabs']//a")
for inner_tab in inner_tabs:
if inner_tab.text == "answers":
inner_tab.click()
time.sleep(3)
driver.get(driver.current_url)
continue
if inner_tab.text == "questions":
inner_tab.click()
time.sleep(3)
driver.get(driver.current_url)
continue
driver.quit()
【问题讨论】:
标签: python python-3.x selenium