【问题标题】:Python selenium: selenium.common.exceptions.NoSuchWindowException: Message: Browsing context has been discardedPython selenium:selenium.common.exceptions.NoSuchWindowException:消息:浏览上下文已被丢弃
【发布时间】:2018-06-13 19:44:11
【问题描述】:

我有以下代码...

# 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)

...执行以下操作:

  1. 实例化 Web 驱动程序
  2. 导航到页面
  3. 点击页面上打开新窗口的按钮
  4. 切换到新窗口
  5. 在新窗口中单击另一个按钮

不幸的是,单击第一个按钮后,新窗口永远不会打开,程序终止并出现以下错误:

selenium.common.exceptions.NoSuchWindowException: Message: Browsing context has been discarded

在今天之前它运行良好,但我不确定发生了什么。有什么想法吗?

【问题讨论】:

    标签: python selenium


    【解决方案1】:

    selenium 无关。手动尝试您的场景时,我在浏览器 DevTools 中得到了这个:

    这是一个网站问题。

    【讨论】:

    • 是的,我遇到了同样的错误。你认为是什么原因造成的?我可以在客户端做些什么吗?
    • 我很确定它无法在客户端解决。我认为最好的方法是将此问题报告给frontend 开发人员。他们可以照顾它。
    【解决方案2】:

    这不是网站问题。 Iterally 它警报为“noSuchWindowException”,对吗?那么浏览器窗口在哪里,它不存在。您已关闭选项卡/窗口。在此基础上根据你的情况找出确切的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-28
      • 2018-11-22
      • 1970-01-01
      • 2019-06-28
      • 2021-05-05
      • 1970-01-01
      • 1970-01-01
      • 2011-07-10
      相关资源
      最近更新 更多