0

When I open page https://the-internet.herokuapp.com/basic_auth I have authentication login popup. How I can click "cancel"?

I tried to dismiss this alert but driver stopped on this code:

driver.Url = "https://the-internet.herokuapp.com/basic_auth"

and I get an error.

This is my code:

    {
        [TestMethod]
        public void TestMethod1()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Url = "https://the-internet.herokuapp.com/basic_auth";

            IAlert alert = driver.SwitchTo().Alert();
            alert.Dismiss();

        }
    }

I have an error message in Visual Studio:

"OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:51508/session/5c55323e7618568db8a156ea224f181e/url timed out after 60 seconds."

supputuri
  • 13,644
  • 2
  • 21
  • 39
josh
  • 1
  • Possible duplicate of [Handle windows authentication pop up on Chrome](https://stackoverflow.com/questions/19357634/handle-windows-authentication-pop-up-on-chrome) – EylM Aug 06 '19 at 18:17

2 Answers2

0

There is no support in the W3C standard for interacting with browser windows such as Basic Authentication, unlike JavaScript Alerts which can be interacted with.

The prompt will prevent the web driver from functioning, locking it's ability to receive commands and preventing it from closing correctly, requiring killing it post run or in a cleanup.

If you have to find a way to handle it you will need to use a 3rd party library such as InputSumulator. Here is a link to the Net Core version: https://www.nuget.org/packages/InputSimulatorCore/

J.D. Cain
  • 639
  • 4
  • 16
0

search for nuget package AutoIT and install it.

In your code add the using statement:

using AutoIt;

Then you will need to add something like the below based on the Window Title. If you go to https://www.autoitscript.com/site/autoit/downloads/ you can download it locally and there is an inspector tool where you can see the popup info like title, class etc.

if (AutoItX.WinExists("https://the-internet.herokuapp.com/basic_auth - Google Chrome") ==  1) //if it displays
{
var winhandle = AutoItX.WinGetHandle("https://the-internet.herokuapp.com/basic_auth - Google Chrome"); //get the window handle
AutoItX.WinKill(winhandle); //close popup
}
Dazed
  • 1,527
  • 1
  • 13
  • 25