How to authenticate alert popup using Selenium
Solution :
Use the following code. Example is given in using Firefox.
String url = "https://dev20.***********.com/************";
String username = "s*****";
String password = "e******";
System.setProperty("webdriver.gecko.driver",
"Geckodriver\\v0.21.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String urlTemp = url.replaceFirst("https://", "");
String URL = "https://" + username + ":" + password + "@" + urlTemp;
driver.get(URL);
...............................................................................................................
My failed attempt #01:
The following code didn't for me & provide Error: "org.openqa.selenium.UnsupportedCommandException: POST /session/ef0fb2c1-e4c1-4d63-bab7-6a8fbe03af8b/alert/credentials did not match a known command"
String url = "https://dev20.***********.com/************";
String username = "s*****";
String password = "e******";
System.setProperty("webdriver.gecko.driver", "Geckodriver\\v0.21.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get(url);
Alert alertObj = driver.switchTo().alert();
alertObj.authenticateUsing(new UserAndPassword(username, password));
alertObj.accept();
My failed attempt #02:
The following code didn't for me & provide Error: "org.openqa.selenium.UnsupportedCommandException: POST /session/ef0fb2c1-e4c1-4d63-bab7-6a8fbe03af8b/alert/credentials did not match a known command"
String url = "https://dev20.***********.com/************";
String username = "s*****";
String password = "e******";
System.setProperty("webdriver.gecko.driver",
"Geckodriver\\v0.21.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get(url);
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alertObj = wait.until(ExpectedConditions.alertIsPresent());
alertObj.authenticateUsing(new UserAndPassword(username, password));
alertObj.accept();
Comments
Post a Comment