How to handle basic authentication pop up in automation tests?

Hi, I am trying to run my selenium tests on lambdatest and I have a basic auth pop up which also has special characters in credentials, it always throws the pop up and i am unable to get past it using the URL. Can someone help ?

Hi Aaron,

You can go through the following approaches to handle basic auth pop up.

  1. Encoding Username:Password if there are any special characters. You can use the https://www.urlencoder.org/ to encode username:password if there are any special characters involved and then use the same in the basic auth URL.

  2. If the above method does not work as expected you can use LT Clipboard and Keyboard events using javascript executor to handle the Basic authentication pop-up in automation tests using selenium.

    Code Snippet:

         driver.executeScript("lambda-set-clipboard:admin");
         driver.get("https://the-internet.herokuapp.com/basic_auth");
         Thread.sleep(2000);
         driver.executeScript("lambda-perform-keyboard-events:^v");
         Thread.sleep(2000);
         driver.executeScript("lambda-perform-keyboard-events:{TAB}");
         Thread.sleep(2000);
         driver.executeScript("lambda-set-clipboard:admin");
         Thread.sleep(2000);
         driver.executeScript("lambda-perform-keyboard-events:^v");
         Thread.sleep(2000);
         driver.executeScript("lambda-perform-keyboard-events:{ENTER}");
    

Hope this helps!

Happy testing!

1 Like