- I am using eclipse JAVA.
When I execute the below code:
public class dbscbg { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://ip/link"); }Authentication pop is seen.
How to handle this?
- Is there a way to inspect pop up using firebug?
- Looked up stackoverflow with the same query but did not understand how can pass username and password via URL.
- Tried below piece of code. Does not work for me.
driver.switchTo().alert().sendKeys("fsdf");
Asked
Active
Viewed 3,821 times
0
Mike Debela
- 1,930
- 3
- 18
- 32
olive silva
- 1
- 2
- 4
-
http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java – Shoaib Mal May 24 '16 at 10:15
1 Answers
0
Hi please do it like below
// waiting till alert is visible
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
or
// alert is already present
Alert alt = driver.switchTo().alert();
if password authentication is necessary then
alt.authenticateUsing(new UserAndPassword(uid, pwd));
Also for more info please visit http://learn-automation.com/handle-windows-authentication-using-selenium-webdriver/
UPDATE
if above is not working then please try like below it will work for sure.I have used java robot class
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.engprod-charter.net/");
Robot rb = new Robot();
//Enter user name by ctrl-v
StringSelection username = new StringSelection("username");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(username, null);
rb.keyPress(KeyEvent.VK_CONTROL);
rb.keyPress(KeyEvent.VK_V);
rb.keyRelease(KeyEvent.VK_V);
rb.keyRelease(KeyEvent.VK_CONTROL);
//tab to password entry field
rb.keyPress(KeyEvent.VK_TAB);
rb.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(2000);
//Enter password by ctrl-v
StringSelection pwd = new StringSelection("password");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(pwd, null);
rb.keyPress(KeyEvent.VK_CONTROL);
rb.keyPress(KeyEvent.VK_V);
rb.keyRelease(KeyEvent.VK_V);
rb.keyRelease(KeyEvent.VK_CONTROL);
//press enter
rb.keyPress(KeyEvent.VK_ENTER);
rb.keyRelease(KeyEvent.VK_ENTER);
Hope this helps you.
Rajnish Kumar
- 2,828
- 5
- 25
- 39
-
Exception in thread "main" java.lang.Error: Unresolved compilation problems: Alert cannot be resolved to a type UserAndPassword cannot be resolved to a type at dbscbg.dbscbg.main(dbscbg.java:15) – olive silva May 25 '16 at 11:32
-
It still throws the same error. Should I import any package for alert? – olive silva May 25 '16 at 12:29
-
Below is my code: package dbscbg; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class dbscbg { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://gehfjklja"); //For authentication Alert alt = driver.switchTo().alert(); alt.authenticateUsing(new UserAndPassword("gfdjfgsj", "jfhgd")); } } – olive silva May 25 '16 at 12:31
-
are you using latest version of selenium or not ? latest is 2.53 – Rajnish Kumar May 25 '16 at 13:01
-
This issue i am facing is in Selenium WEBDRIVER. I am using Java EE IDE for coding. – olive silva May 30 '16 at 09:23