user3555007
user3555007

Reputation:

Selenium + Python - Handling Authentication Dialog without URL username and password params

I need to authenticate myself without giving the params in the URL. This means, I have to handle the alert manually (This means, switching to the alert, authenticate, switching back to the previous window) and use the authenticate method provided by Selenium Alert Class.

This is the function i'm using to handle the alert:

def login_browser_alert(driver):
    WebDriverWait(driver, 3).until(EC.alert_is_present())
    current_window = driver.window_handles[0]
    driver.switch_to.alert.authenticate('admin', 'admin')
    driver.switch_to.window(current_window)

This is how I navigate to the page:

def goto_page(self):
        self.driver.get(self.URL)
        login_browser_alert(self.driver)

I'm using http://the-internet.herokuapp.com/basic_auth as a dummy Authentication example. Credentials are user: "admin" pass: "admin"

The problem:

Nothing happens. The dialog just remains there and no input will be sent in any field. Nothing will be clicked. It just, hangs, there.

All solutions I find are just passing the params in the URL like this:

http://admin:[email protected]/basic_auth

Which I can't for some reasons specific to the project i'm currently working on. So, no, this won't solve my problem...

Did someone encounter a similar problem? How did you resolve this issue?

EDIT:

In this link you can find more about this issue.

https://github.com/SeleniumHQ/selenium/issues/5471#issuecomment-364457555

The method authenticate in the Alert class was just experimental. Seems like the only way is indeed with the URL Parameters.

Upvotes: 0

Views: 987

Answers (1)

Ian Lesperance
Ian Lesperance

Reputation: 5139

Alert#authenticate() likely does nothing. It was removed from the Ruby and Java bindings and there are no tests for it in the Python bindings.

As you've seen elsewhere, your only option is to include the username and password in the requested URL as username:password@host.

Upvotes: 1

Related Questions