Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 880
Brinley Avatar asked Jun 13 '18 19:06

Brinley


1 Answers

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.

like image 151
Andrei Suvorkov Avatar answered Nov 08 '22 03:11

Andrei Suvorkov