Reputation: 573
Have tried several approached to handle it but none worked.
https://user:[email protected]
- doesn't work, chrome launches controlled bu automates test software and authentication pop-up appears anyway.
Adding --disable-blink-features=BlockCredentialedSubresources
to Chrome arg and repeat 1'st point - doesn't work, reason the same as in 1'st point.
driver.switchTo().alert.authenticateUsing(new UserAndPassword(user, password))
- here seems like driver doesn't see an alert, have impelented method that checks it and returns false:
private Alert alert;
public boolean isAlertPresent() {
try {
waitForTimeout(10, TimeUnit.SECONDS);
alert = driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}}
Triggering keyboard or mouse event via selenium Action()
doesn't work too.
chromedriver 2.31
Google Chrome Version 61
Any other ideas ? Maybe some js script ?
Upvotes: 3
Views: 2542
Reputation: 125
I had something similar here. you may not need the full Native Messaging API, though ... This will all be JavaScript and will work for any browser-generated auth request (at least, it looks that way).
webRequest - chrome and firefox - has an anAuthRequired event. You can hook into this with a listener then just pass in the credentials you need per some examples.
If you're wanting to just pass in user credentials that won't change, you'll want to use the synchronous method - it's much easier. This question may, indeed, be all you need.
If you're needing to pass in different credentials, you may well want to look into the asynchronous method, that's the one I had to use. If you're using chrome, forget promises ... but Firefox should work with them.
Hope this helped!
Upvotes: 1
Reputation: 573
Finally - I was able to do it by Robot Framework which is not a solution that I am proud of, but didn't have any other idea.
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
private Robot robot;
public void login(String login, String password) {
copyValueFromClipboardToInput(login);
getRobot().keyPress(KeyEvent.VK_TAB);
getRobot().keyRelease(KeyEvent.VK_TAB);
copyValueFromClipboardToInput(password);
getRobot().keyPress(KeyEvent.VK_ENTER);
getRobot().keyRelease(KeyEvent.VK_ENTER);
}
private void copyValueFromClipboardToInput(String value) {
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(value), null);
getRobot().keyPress(KeyEvent.VK_CONTROL);
getRobot().keyPress(KeyEvent.VK_V);
getRobot().keyRelease(KeyEvent.VK_V);
getRobot().keyRelease(KeyEvent.VK_CONTROL);
}
private Robot getRobot() {
if (robot == null) {
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
}
return robot;
}
Upvotes: 0