How to pass authentication pop up in selenium?

Question:

I’m trying to load a web page that requires authentication using Python script with Selenium.

options = webdriver.ChromeOptions()
prefs = {'download.default_directory': r"download.default_directory=" + download_folder,
         "download.prompt_for_download": False, 'profile.default_content_setting_values.automatic_downloads': 1}
options.add_experimental_option('prefs', prefs)
options.add_argument("--start-maximized")
options.add_argument('--disable-browser-side-navigation')
driver = webdriver.Chrome(chrome_options=options, executable_path=chrome_driver)
driver.get('https://user:[email protected]/32324')

This still gets the popup alert with user name and password.
So, I figured I’ll just handle the alert in code but it seems the page doesn’t finish loading until the alert is closed so the script is stuck on the get function.
How do I handle this situation?

EDIT: This is not duplication because the accepted answer there doesn’t work for me.

Asked By: talon

||

Answers:

try this…

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);

options.setExperimentalOption("prefs", prefs);
Answered By: Sandeep Raulo

After many hours wasted, it turns out that it is a known issue with chromedriver:
https://bugs.chromium.org/p/chromedriver/issues/detail?id=1917&q=authentication&colspec=ID%20Status%20Pri%20Owner%20Summary

I switched to using Firefox instead and it works from there.

Answered By: talon

In case you mean html basic authentification you can also try the following workaround: (Sorry I just know Java but it should be quite similar)

driver.get("http://[USERNAME]:[PASSWORD]@[rest of the Page-URL you want to 
enter]");
driver.get("[normal URL of the page you want to enter]");

The 2nd driver call is just reloading the page. I don´t know if you need it, but for my automation it´s needed.

Answered By: Arno Don Calzone

Try using autoit:

The code goes something like ::

from selenium import webdriver
import autoit
driver= webdriver.Chrome()
driver.get("http://sitewithpopup.com")
autoit.win_wait_active("",30) # Make sure you give blank since the cursor is at userid
autoit.send("Username{TAB}")
autoit.send("Password{Enter}")

Since the autoit will type wherever your cursor is and by default the cursor is on the userID field so you can make use of it.

Answered By: Mayank Mani Jha

So this might be the dumbest solution, and I can’t say it’ll work for everyone but… Try refreshing the page. Just:

driver.get("https://website.com")
time.sleep(1)
driver.refresh()

In Chrome this cleared the Authentication popup and took me to the login page, which Selenium could then handle.

Answered By: TechnoWolf