问题
I have the url which needs credentials and I am navigating to that through selenium + Java https://username:password.example.com/
However it still shows the login window but not as an alert window. Attached the screenshot. I tried the below code but it did not work
UserAndPassword UP = new UserAndPassword("username","password");
driver.switchTo().alert().authenticateUsing(UP);
Is there anyway I can do it?
回答1:
You are missing @ symbol after user name and password. You can try like below,
https://username:password@test.discoverykidsplay.com/
回答2:
This provides multiple approaches for handling Authentication pop-ups.
I would suggest to
use WebDriver’s switchTo.alert() syntax to access them and then use methods such as sendKeys(), accept() or dismiss()
来源:https://stackoverflow.com/questions/44722353/how-to-login-to-the-alert-window-when-we-navigate-to-the-browser-through-seleniu