Search code examples
javaseleniumselenium-webdriverhtmlunithtmlunit-driver

How to handle a window based authentication in HTMLUNIT driver


I wanna run my test cases in headless mode, and I picked HtmlUnit is the way to achieve my requirement. But, the initial page where I need to handle windows based authentication box, and based on valid authentication it will take me to summary page of my application. We can able to handle the window based pop up by using Robot class, or AUtoIT but I'm not sure how that handled in headless mode. Can somebody help me on this? How do I bypass the authentication window in headless mode. I surfed and found there was some solution by using https://username:password@url, but it doesn't help me to fix my issue.

Note : I'm using Selenium JAVA libraries.


Solution

  • You can do it by using following code in selenium webdriver:

    var alert = driver.SwitchTo().Alert();
    alert.SetAuthenticationCredentials("username", "password");
    alert.Accept();