在我的方案中,当我启动URL时,会打开一个身份验证警报窗口,我需要从excel输入用户名和密码,然后点击“登录”它会显示我的网页主页。我使用下面的代码片段实现了它,它在IE11中完美运行。但是,当我尝试在Chrome v60中运行相同的代码时,它无效。它显示了身份验证警报窗口,但未对其执行任何操作。附上截图。有人可以建议吗。
Selenium WD版本 - 3.4.0
代码:
public static void loadApplicationURL(WebDriver driver) throws Exception
{
String SSPathl = null;
String URL = Generic_Functions.GetParameterFromInputSheet("URL");
try
{
driver.get(URL);
Thread.sleep(6000);
LoginApplication.isAlertPresent(driver);
}
}
public static boolean isAlertPresent(WebDriver driver) {
try {
driver.switchTo().alert();
UserAndPassword UP = new UserAndPassword(UserName,Password);
driver.switchTo().alert().authenticateUsing(UP);
Thread.sleep(8000);
return true;
}
catch (Exception e) {
return false;
}
}
对于测试浏览器,创建了一个单独的类。在下面找到用于IE和Chrome浏览器的代码段。
适用于Chrome
System.setProperty("webdriver.chrome.driver",".\\Resources\\chromedriver.exe");
driver = new ChromeDriver()
如果是IE,
[System.setProperty("webdriver.ie.driver",".\\Resources\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
ieCapabilities.setCapability("nativeEvents", true);
driver = new InternetExplorerDriver(ieCapabilities);][1]