我有以下代码......
# instantiate web driver
profile = webdriver.FirefoxProfile("C:\\Users\\me\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\me.default")
driver = webdriver.Firefox(firefox_profile=profile)
driver.wait = WebDriverWait(driver, 5)
# browse to bot detection page
driver.get("https://botometer.iuni.iu.edu")
# click dropdown button on navbar
button = driver.wait.until(EC.presence_of_element_located((By.CLASS_NAME, "dropdown-toggle")))
button.click()
# click login link
login_link = driver.wait.until(EC.presence_of_element_located((By.LINK_TEXT, "Log In")))
login_link.click()
# switch to authorize window
new_window = driver.window_handles[1]
driver.switch_to.window(new_window)
# click authorize button
authorize_button = driver.wait.until(EC.presence_of_element_located((By.ID, "allow")))
authorize_button.click()
time.sleep(5)
......执行以下操作:
不幸的是,在单击第一个按钮后,新窗口永远不会打开,程序会以此错误终止:
selenium.common.exceptions.NoSuchWindowException: Message: Browsing context has been discarded
今天工作正常,我不确定发生了什么。有什么想法吗?