8

I have the following code ...

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

... that does the following:

  1. Instantiates a web driver
  2. Navigates to a page
  3. Clicks on a button on the page that opens a new window
  4. Switches to the new window
  5. Clicks another button in the new window

Unfortunately, after the first button is clicked, the new window never opens, and the program terminates with this error:

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

It was working fine before today and I'm not sure what happened. Any ideas?

Brinley
  • 591
  • 2
  • 14
  • 26

2 Answers2

3

It has nothing to do with selenium. I'm getting this in browser DevTools when trying your scenario manually:

img

It's a website issue.

Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48
  • Yeah I'm getting the same error. What do you think is causing it? Is there anything I can do on the client side? – Brinley Jun 13 '18 at 19:54
  • I pretty sure that it cannot be resolved on client side. I think the best way is to report this issue to `frontend` developers. They can take care about it. – Andrei Suvorkov Jun 13 '18 at 19:57
0

it's not website issue. Iterally it alerts as "noSuchWindowException", right? so where is the browser window, it's not existing. you've closed the tab/window. Based on this to find the exact reason by your situation.

sampan0423
  • 89
  • 6