This question comes up a lot. Here is a possible solution, but it will require some additional development. You could use a customized HTTP proxy that acts as a pass-through filter except when it sees an HTTP 401 response. In the latter case, the proxy would respond with authentication credentials of your choosing.
Here is how you might do it, in steps:
- Find an HTTP proxy that you can modify in whatever language you use for your test. For brevity, I will assume you are using Java, so you want an HTTP proxy written in Java. (See https://stackoverflow.com/questions/860362/write-http-proxy-in-java for more details on open source, Java, HTTP proxies.)
- Presumably you have some means of determining second, dynamically-generated password, and the details of that are not important. I will call that mechanism the "OTP oracle". You need to write a Java method that can ask the OTP oracle for the next OTP.
- Modify the HTTP proxy to respond to 401 responses by asking the OTP oracle for the next password and responding back to the server with a new HTTP request with the appropriate credentials.
- Embed the HTTP proxy in your test, i.e. code your test so that at start-up, it launches the HTTP proxy in a separate thread.
- Tell Selenium to launch the browser so that it uses your HTTP proxy.