如何处理身份验证弹出

时间:2016-05-05 07:05:05

标签: selenium

请看下面的图片

enter image description here

我需要发送电子邮件,密码并单击“确定”。我试过Action,Robot类。但是没有用。

2 个答案:

答案 0 :(得分:1)

你可以使用如下: -

driver.get("http://UserName:Password@Example.com");

使用您的用户名代替用户名,密码相同,并将example.com更改为您的网站

OR

WebDriverWait wait = new WebDriverWait(driver, 20);      
Alert alert = wait.until(ExpectedConditions.alertIsPresent());     
alert.authenticateUsing(new UserAndPassword(**username**, **password**));

希望它会对你有所帮助:)。

答案 1 :(得分:1)

作为警报,URL中的机器人和用户名/密码不起作用,因此您可能需要尝试创建配置文件并调用它,如果它在此工作,或者转到AutoIT ..

我更喜欢,通过提供名称来创建自己的firefox配置文件。 Here是步骤

创建配置文件后,手动导航到URL并提供这些身份验证并保存这些身份验证。正如你下次保存的那样,如果你开始使用相同的配置文件,它不会问,对吗?

所以请调用已保存的个人资料

 ProfilesIni profile = new ProfilesIni();

 FirefoxProfile myprofile = profile.getProfile("savedProfile");

  WebDriver driver = new FirefoxDriver(myprofile);

谢谢你, 穆拉利