尝试使用此代码关闭新窗口并切换回主窗口
from selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as EC# Get current windowcurrent = self.driver.current_window_handle# Get current windowshandles = self.driver.window_handles# Click button. Consider to use more reliable relative XPath instead of this absolute XPathself.driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[2]/div[1]/section[1]/div[1]/div[1]/div[2]/div[1]/a[1]/img[1]").click()# Wait for new windowWebDriverWait(self.driver, 10).until(EC.new_window_is_opened(handles))# Switch to new windowself.driver.switch_to.window([w for w in self.driver.window_handles if w != current][0])# Close new windowself.driver.close()# Switch back to main windowself.driver.switch_to.window(current)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)