17

For a long time I've been using a python bot to do some work task. Among others things, the bot has to pass an authentication window.

The code of this in the python program is the following:

driver = webdriver.Firefox(firefox_profile=profile)
...
driver.get('https://example.com')
driver.switch_to.alert.send_keys('123456' + Keys.TAB + '123456')
driver.switch_to.alert.accept()

But yesterday it throwed this error:

selenium.common.exceptions.WebDriverException: Message: User prompt of type promptUserAndPass is not supported

I've been googling but I even don't find results about this kind of exception and how to deal with this problem.

Any ideas?

Thanks in advance!

tec
  • 999
  • 3
  • 18
  • 40
cooper
  • 635
  • 1
  • 8
  • 23

2 Answers2

11

It seems that HTTPAuth dialogs are not supported by any drivers at the moment.
Firefox implemented an workaround which does not work anymore in 67.0. It appears they cannot start adding support for the HTTP authentication prompt right now, due to missing specifications.

https://bugzilla.mozilla.org/show_bug.cgi?id=1556026

https://bugzilla.mozilla.org/show_bug.cgi?id=1556307

https://github.com/w3c/webdriver/issues/385

I've managed to workaround this problem by installing Firefox 66.0 under a different name and then mentioning its location when calling the FirefoxDriver, like @elead1 did.

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver import Firefox

path = FirefoxBinary("/path/to/Firefox2/firefox-bin")
browser = Firefox(firefox_binary=path)
elinnore
  • 126
  • 4
  • I could also get past this problem by setting the username / password with my Firefox profile and then assigning the test to use my own profile rather than an ad hoc test profile. Then you'll just want to accept the prompt to get past the authorization. You could also try to set the Authorization header using python -- Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ= , where the string is "username:password" encoded with Base64. I'm using robot so this is not an option. – sampoh Nov 27 '19 at 08:23
7

I don't have enough rep to comment and I know this isn't "solving" the problem, but I was able to work around this problem by using the Firefox ESR.

You can install the ESR parallel to your main Firefox installation, and then specify which binary the FirefoxDriver will use:

driver = webdriver.Firefox(firefox_profile=profile, firefox_binary="/path/to/esr/binary")
elead1
  • 173
  • 1
  • 7
  • still the same exception: selenium.common.exceptions.WebDriverException: Message: User prompt of type promptUserAndPass is not supported – bzhu Dec 10 '19 at 02:58
  • Which version of Firefox ESR did you install? There's a good chance the newest version (68.3) has also removed the necessary functionality. When I posted my answer, I believe I was using 66, or possibly 60. – elead1 Dec 11 '19 at 04:55
  • just checked, as my company pushed down a newer version of Firefox which broke my scripts. 60.1.0 ESR works, 60.9.0 ESR works, Firefox 66.0.5 (non-esr) works. multiple 68.x.0 ESR versions do NOT work. https://ftp.mozilla.org/pub/firefox/releases/ – Brian W Sep 29 '20 at 20:45