Selenium is purely used for automating of repeatative Manual Tasks. At this point it is worth to mention that Selenium mocks User Interactions.
Hence the statement once user authenticates the log in, selenium takes over the browser is pretty much speculative as attempting to Reconnect Selenium to previous Browsing Session is not viable.
Now the statement, "code may fail if user accidentally clicks anything" is pretty much expected as Selenium needs browser focus. As a result of any manual user interaction Selenium will loose focus and raise an error.
Finally, there is no other way to prevent manual inputs as mentioned earlier that Selenium mocks User Interactions. The best possible way to execute your Selenium based Automated Tests preventing manual inputs from the user would be to :
- Set up a Test Bed with all the required Hardware and Software configuration.
- Create the Test Bed in an isolated environment preferably in a Test Lab free from Manual Intervention.
- Automate only the required usecases which needs no manual intervention.