Please note that my question is not a duplicate of Python Selenium Alert -- Prompt username and password is not working. In my case it's not working for Chrome not Firefox, for Firefox it is working. Also I've tried the solution provided in the bug and it didn't work for Chrome.
Here is the code sample
wait(driver, 5).until(EC.alert_is_present())
alert = driver.switch_to_alert()
alert.send_keys("username" + Keys.TAB + "password")
alert.accept()
Expected behavior is - keys are correctly send to popup.
I'm getting timeout exception on line 1 - selenium.common.exceptions.TimeoutException: Message:
when actually the alert is present. authentication popup
When removing line 1, I'm getting exception on line 2 selenium.common.exceptions.NoAlertPresentException: Message: no alert open
Any ideas on this? How can I pass the credentials with chromedriver? Also I'll need to be able to perform this in headless mode on linux commandline server.
I've found workaround:
def __getCapabilitiesForChrome(ip, port, user, password):
proxy = {'address': user + ":"+password+"@"+ip + ':' + str(port),
'username': user,
'password': password}
capabilities = dict(DesiredCapabilities.CHROME)
capabilities['proxy'] = {'proxyType': 'manual',
'httpProxy': proxy['address'],
'ftpProxy': proxy['address'],
'sslProxy': proxy['address'],
'noProxy': '',
'class': "org.openqa.selenium.Proxy",
'autodetect': False}
return capabilities
capabilities = __getCapabilitiesForChrome(ip, port, username, password)
driver = webdriver.Chrome(executable_path='chromedriver.exe', desired_capabilities=capabilities)
driver.get('https://www.foo.bar/')
But actual sending keys is not implemented yet https://github.com/w3c/webdriver/issues/385.