0

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.

3
  • Can you help us to understand I have to handle the alert manually and use the authenticate method provided by Selenium Alert Class please?CommentedFeb 9, 2018 at 10:47
  • You can see what I mean with the method login_browser_alert. Handling the alert manually means to me: Switching to the alert, use the authenticate method, switch back to the previous window.
    – user3555007
    CommentedFeb 9, 2018 at 11:34
  • See, you are mixing up 3 different things here. First of all you want us to believe its a Authentication Dialog which is neither an Alert nor have a separate WindowHandle , then you induce WebDriverWait for an Alert & use switch_to.alert but finally you are trying to use switch_to.window . So where exactly do you want us to help you without any concrete information about the element with whom you want to interact with?CommentedFeb 9, 2018 at 11:53

1 Answer 1

1

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.

1
  • Hey Ian. Thank you! I posted this also as a Selenium Issue and they said the same thing. I will edit the Question to add a link to that issue.
    – user3555007
    CommentedFeb 9, 2018 at 15:17