When trying to run the following code

drive = webdriver.Chrome(chromedriver_locator) drive.get(any_syte) drive.close() drive.get(any_syte) 

I get an error WebDriverException: Message: no such session Is it possible to close and then open a new window within the same web session?

  • Do you have the only open window? Just if you close a single window, the browser also closes. - Andrew Bystrov
  • Yes, the window is the only one. The point is to rediscover the closed window. - Vindict
  • and you can not just zarefreshit it? - Andrew Bystrov
  • refresh () did not help, I try to restart the web session - Vindict

1 answer 1

Try after close , call the drive.start_session({}) method, since when you call the close method, the open session is closed.

 drive = webdriver.Chrome(chromedriver_locator) drive.get(any_syte) drive.close() drive.start_session({}) drive.get(any_syte) 
  • Thank you very much. Works - Vindict
  • You already passed the settings when creating the Chrome object When you call start_session, you simply create another session with a new window with the same parameters. To do this, just pass the empty dictionary with the first argument. If you want to change some settings, you can pass the dictionary with the new desired_capabilities . - Avernial