0

Can't enter username into popup authentication window Java, selenium (in Safari and Opera)

This constriction doesn't work both in Safari and Opera:

driver.get(“https://username:password@example.com”)

And this doesn't work too:

Alert alert = driver.switchTo().alert();
alert.sendKeys("Test"); //that is how I am trying to enter login

Thank you in advance!

Yuliia
  • 1
  • What error are you getting? Can you share an error logs? – Ali Feb 04 '19 at 15:46
  • I have a message in logs INFO: Detected dialect: W3C And test continues to run. Browser window stays opened with authentication popup in it. – Yuliia Feb 04 '19 at 16:03
  • @Yuliia have you given any sleeps before switching to Alert? Please share full code. – Jitendra Banshpal Feb 04 '19 at 17:09
  • Just try to remove `sleep(5000)` and run the code. And use `Thread.sleep(5000)` – Jitendra Banshpal Feb 04 '19 at 17:20
  • This is my code. I've tried both with and without sleep: `public class BasePage { private WebDriver driver; public BasePage(WebDriver driver){ this.driver = driver; } public void visit() { driver.get(baseURL + projectTest); sleep(5000); Alert alert = driver.switchTo().alert(); alert.sendKeys("Test"); driver.manage().window().maximize(); } ` – Yuliia Feb 04 '19 at 17:22
  • @JitendraBanshpal I've tried both with and without sleep. my sleep is a separate method ` public static void sleep(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { throw new RuntimeException(e); } }` Sorry, there were no space to include it all in one message. – Yuliia Feb 04 '19 at 17:25
  • @Yuliia, try this `public class BasePage { private WebDriver driver; public BasePage(WebDriver driver){ this.driver = driver; } public void visit() throws Exception { driver.get(baseURL + projectTest); driver.manage().window().maximize(); Thread.sleep(5000); Alert alert = driver.switchTo().alert(); alert.sendKeys("Test"); } }` – Ali Feb 04 '19 at 17:26
  • Have you considered the possibility that the pop-up is not an alert at all? Alerts usually do not prompt for input other than accept or dismiss, and the alert type has those specific methods. If it's asking for login credentials, it's likely part of the page's DOM. Use tools to check the web elements for locators and treat it like the rest of the document. – Bill Hileman Feb 04 '19 at 17:45
  • The pop-up belong to OS = not reachable by selenium. Try driver.get("https://username:password@example.com") instead of driver.get(“https://username:password@example.com”). But I still doubt it will work in all browsers. Better to use existing browser profile with saved credentials (if possible). – pburgr Feb 05 '19 at 07:58
  • Hi @pburgr thank you for your reply! Could you please repeat the variant instead of driver.get(“username:password@example.com”). I think there is a typo because 2 constructions are the same. – Yuliia Feb 05 '19 at 10:12
  • “xy” vs "xy" different quation marks. In code use " instead of “ / ” – pburgr Feb 05 '19 at 11:56

0 Answers0