硒警报认证 [英] Selenium alert authentification
问题描述
我正在尝试访问位于我的本地主机上的网站.当我导航到它时,会出现一个警报,并且我必须进行身份验证,但是当我使用方法"authenticateUsing"时,它表明不存在该警报.谁能帮我?
I am trying to access a website located on my localhost. When I navigate to it, an alert appears and I have to authenticate, but when I use the method "authenticateUsing", it shows me that it does not exist. Can anyone help me?
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.navigate().to("http://localhost:8015/thing/Home");
String username = "a";
String password = "bbbbb";
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword(username, password));
错误看起来像:
我要填写这样的警报:
I want to fill an alert like this one:
推荐答案
该问题并未提供足够的信息.我会给你一些方法:
This question does not provide enough information though. I will give you some Approaches :
方法1:
要进行交互,必须先切换到警报框.
You have to switch to alert box before you want to have interaction.
Alert alert = driver.switchTo().alert();
然后,您可以继续执行.切换到警报后类似这样:
Then you can proceed further in your execution. Something like this after switching to alert :
wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword(username, password));
方法2:
String username = "a";
String password = "bbbbb";
String URL = "http://" + username + ":" + password + "@" + localhost:8015/thing/Home;
driver.get(URL);
Alert alert = driver.switchTo().alert();
alert.accept();
方法3::您可以尝试使用AutoIT脚本.请注意,AutoIT脚本仅在Windows环境中有效.但是,我不建议您采用这种方法.
Approach 3 : You may try AutoIT script. Please note that AutoIT script will work only in windows environment. However, I would not recommend you to go with this approach.
这篇关于硒警报认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!