我有以下代码...
# 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
在今天之前,它工作得很好,我不确定发生了什么。有什么想法吗?
发布于 2018-06-14 03:48:27
这与selenium
没有任何关系。在手动尝试您的方案时,我在浏览器DevTools
中获得了以下内容:
这是一个网站的问题。
发布于 2021-01-16 22:30:04
这不是网站的问题。通常它的警报是"noSuchWindowException",对吧?那么浏览器窗口在哪里,它并不存在。您已关闭选项卡/窗口。在此基础上,根据您的情况找到确切的原因。
https://stackoverflow.com/questions/50845079
复制相似问题