Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate basic authentication chrome alert

Chrome authentication popup

Have tried several approached to handle it but none worked.

  1. https://user:[email protected] - doesn't work, chrome launches controlled bu automates test software and authentication pop-up appears anyway.

  2. Adding --disable-blink-features=BlockCredentialedSubresources to Chrome arg and repeat 1'st point - doesn't work, reason the same as in 1'st point.

  3. 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; }}

  4. 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 ?

like image 970
Michal Avatar asked May 04 '26 05:05

Michal


1 Answers

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!

like image 50
Lex Woodfinger Avatar answered May 05 '26 18:05

Lex Woodfinger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!