0

My problem:

Currently I need to open a site where I need to put user and password in the chrome authentication window, but I'm trying the only alternative I found on the internet, but without success

enter image description here

I tried this:

https://myuser:mypassword@mysite.com

but this is not solving because in this format the website is not opening, much less authenticating with the credentials in the url

my stack:

Python 3 + Selenium 3.3.3 + Chrome 60

Rafael C.
  • 2,245
  • 4
  • 29
  • 45
  • Possible duplicate of [Python Selenium Alert - Prompt username & password is not working](https://stackoverflow.com/questions/45328654/python-selenium-alert-prompt-username-password-is-not-working) – undetected Selenium Sep 08 '17 at 09:32

2 Answers2

0

Idk about python but in c# you can handle it as follows;

var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("username", "password");
alert.Accept();
-1

You might need to use a plugin, like I had to. This question/answer details how I solved the problem in Chromium/Chrome ...

Solution:

This was implemented in python 2.7 But there shouldn't be too much difference to make it work in 3.X

You're going to need to use a browser extension. My solution has been built for chromium but it should port almost-unchanged for Firefox and maybe edge.

First up, you need 2 APIs to be available for your browser:

While both browser APIs are very similar, they do have some significant differences - such as Chrome's implementation lacking Promises.

If you setup your Native Messaging Host to send a properly-formed JSON string, you need only poll it once. This means you can use a single call to runtime.sendNativeMessage() and be assured that your credentials are paresable. Pun intended.

Next, we need to look at how we're supposed to handle the webRequest.onAuthRequired event.

Since I'm working in Chromium, I need to use the promise-less Chrome API.

chrome.webRequest.onAuthRequired.addListener(
  callbackFunctionHere,
  {urls:[targetUrls]},
  ['asyncBlocking'] // --> this line is important, too. Very.

The Change:

I'll be calling my function provideCredentials because I'm a big stealy-stealer and used an example from this source. Look for the asynchronous version.

The example code fetches the credentials from storage.local ...

chrome.storage.local.get(null, gotCredentials);

We don't want that. Nope.

We want to get the credentials from a single call to sendNativeMessage so we'll change that one line.

chrome.runtime.sendNativeMessage(hostName, { text: "Ready" }, gotCredentials);

That's all it takes. Seriously. As long as your Host plays nice, this is the big secret. I won't even tell you how long it took me to find it!

Links:

My questions with helpful links:

  • Here - Workaround for Authenticating against Active Directory
  • Here - Also has some working code for a functional NM Host
  • Here - Some enlightening material on promises
Lex Woodfinger
  • 125
  • 1
  • 9