BasePage:
# 窗口切换
def switch_handles(self):
handles = self.driver.window_handles
try:
self.driver.switch_to.window(handles[-1])
logger.info("Switch to window :%s" % self.driver.current_window_handle)
except NameError as e:
logger.error("Failed to switch other window")
Test:
homepage = HomePage(self.driver)
homepage.click_news_link()
newspage = NewsHomePage(self.driver)
newspage.switch_handles()
newspage.click_sports()
报错:selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
求大神解惑,网上有说重新定位元素,但重新定位不就失去了 po 封装的意义啦