Handling Authentication Popup in Selenium

Profile picture for user arilio666

Have you ever wandered into a page with an authentication popup asking for a username and password from you to see the contents of the page?

In this article, we will see how we can bypass this popup.

  • It looks like this when we access a specific page with the popup.
     

Let us see how we can handle this.

Passing Credentials In The URL

  • The popup occurs with the username and password authentication in most cases, so to bypass it, we can pass in the username and password with the URL where it has the authentication popup.
  • It goes something like this.
https://username:password@URL
  • Let us check it out in realtime.
        WebDriverManager.chromedriver().setup();
        ChromeDriver driver = new ChromeDriver();
        String username = "admin";
        String password = "admin";
        String URL = "https://" + username + ":" + password + "@" + "the-internet.herokuapp.com/basic_auth";
        driver.get(URL);
  • So here, we stored the username and password in a variable and passed it inside the URL variable like the format.
  • We can see it has been bypassed successfully using this method.