User should not be able to close the browser using following methods.

1)Clicking X button of browser window
2)Using Alt+F4 
3)Right-Click on Taskbar Icon + Close Window 

Edit :

We require this setup to run uninterrupted test on a machine that would be accessed by users and would have separate applications running at the same time of this test run. So we want to avoid our browser being messed around during that period. just want to run the tests in locked manner in a browser. User should be free to do anything else on that machine.

  • 2
    Is this some sort of a test? To verify that user is unable to close the Chrome browser? Are you doing functional test of your web application or you testing Chrome browser itself? Commented Oct 16, 2017 at 13:44
  • 1
    Looks like you're trying to write a sort of malware, that would perform actions in web browser and is supposed to prevent user's attempts to interrupt those interactions. Could you share how this requirement is relevant to the testing.
    – Alexey R.
    Commented Oct 16, 2017 at 13:47
  • 1
    Please read how to ask as it is unclear what you are trying to solve, what you have done yourself and what is not working. In this specific case I can imagine that people would start to question your motives: why would you ever want to prevent this?
    – Ray Oei
    Commented Oct 16, 2017 at 14:39
  • I have edited the question Commented Oct 17, 2017 at 4:15
  • selenium doesn't close the browser until you call quite or close method
    – NarendraR
    Commented Oct 17, 2017 at 4:28

1 Answer 1


While Selenium can not prevent users from closing the browser, there are other ways you can achieve uninterrupted test execution.

Option 1: Use headless chrome

With chrome v60+ for windows, you can run chrome headless. This means the browser will not pop up on the screen so users will not be interrupted. It will however, still pop up the chrome icon on the toolbar. Clicking on this icon will not bring up the browser, but users can still right click and quit it. The other downside is you won't be able to watch tests run in real time anymore. If you want to use chrome headless, you just need to add chromeOptions to your chromedriver initialization. Here's an example in java:

ChromeOptions chromeOptions = new ChromeOptions();
Webdriver driver = new ChromeDriver(chromeOptions);

Option 2: Setup Selenium Grid and run Selenium Standalone as a Service

If you don't want your user to even see the Chrome icon appear on the toolbar, then I would setup selenium grid and run the Selenium Standalone as a Windows Service (NSSM is a nice tool for this). This would run the test in Session 0 in the background where it is completely invisible to the user, hence will have no way of interrupting it. You can still see screenshots of any running tests by going to the selenium hub portal. The setup for this is more involved, but I would recommend this option for the long run for scalability. It will also fit very well if you intend to move towards Continuous Integration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.