Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed

Ask Question

I have a python script that I am running on one PC and want to move it to a remote PC that runs 24/7. It worked for a while and then it stopped from one day to the next. Now it gives me the error message that the window already closed is, when in fact is not. I have updated selenium together with all other libraries on both computers and the Chrome driver and still on the old PC the script works without a problem, but on the new one it doesn't work. Even added Chrome options and still nothing.

  • there is no iframe in on the target website, nor has there ever been
  • updated all libraries and chrome drivers and both PCs
  • added chrome options that should have helped, but didn't
  • chromeOptions = webdriver.ChromeOptions()
    prefs = {"download.default_directory": download_dest}
    chromeOptions.add_experimental_option("prefs", prefs)
    # chromeOptions.add_argument("--headless")
    # chromeOptions.add_argument('--start-maximized')
    chromeOptions.add_experimental_option("detach", True)
    chromeOptions.add_argument('disable-infobars')
    chromeOptions.add_argument('--disable-extensions')
    chromeOptions.add_argument('--no-sandbox')
    chromeOptions.add_argument('--disable-dev-shm-usage')
    chromeOptions.add_argument('--disable-gpu')
    chromeOptions.add_experimental_option("excludeSwitches", ["enable-logging"])
    driver = webdriver.Chrome(service=Service(driver_path), options=chromeOptions)
    
  • rewiring the script even and still nothing
  • security rights, certificates, proxies etc. are all the same for both machines.
  • Everything works on the old PC, but on the new nothing helped. Both run the same version of python and all the libraries are the same as well.

    Issue was isolated to task scheduler. This is a script that runs on a daily basis, thus the task scheduler. The script runs normally when called from the command prompt on the new and also from PyCharm on the new PC. The new PC is also less powerful compared to the old one, however, this shouldn't be a factor as I am able to run the script fine in command prompt.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.