'C# Why switch to alert not detected in Chrome selenium

I know that this question asked tens of times but still no answer working.

I’m using Selenium 4 with Chrome 99 and here’s the code:

var options = new ChromeOptions();
string StrProxy = "ip:port";
Proxy p = new Proxy();

p.HttpProxy = StrProxy;
p.SslProxy = StrProxy;
p.Kind = ProxyKind.Manual;
options.Proxy = p;

var driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://myip.com");
//driver.Navigate().GoToUrl("https://username:[email protected]"); not working


WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until(ExpectedConditions.AlertIsPresent());
var alert = driver.SwitchTo().Alert();

/* get an error:
OpenQA.Selenium.NoAlertPresentException: 'no such alert 
(Session info: chrome=99.0.4844.51)'*/

alert.SetAuthenticationCredentials("username", "password");
alert.Accept();


Solution 1:[1]

  1. Try a higher wait time value:

    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));    
    
  2. Make sure that manually - an alert is actually showing up. Don't just switch to the alert, accept it:

    driver.SwitchTo().Alert().Accept();
    

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tal Angel