'"NoAlertPresentException:mesage: No such alert" when using selenium webdriver

I tried everything I can find online, still can't solve this issue. I am using selenium to login a site. There is a javascript login popup windows that requires username and password. enter image description here Below is the code which doesn't work.

driver.get(url)
sleep(5)
alert=driver.switch_to.alert

I also tried use request.get(https://username:password@site), it works, but I can't get the content after login. I assume it is javascript page. Anyone can help me with this issue. I would really appreciate. I have worked on this issue for whole day long.



Solution 1:[1]

This is not an alert, rather an example of a page with basic authentication. If you are using Selenium4, then here is an article by Simon Stewart about how you can handle this - link

Also, you can see this blog post which takes a slightly different approach to same problem, using Selenium 4 and Chrome Devtools - link

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 demouser123