0

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:pass@somepage.com/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.

talon
  • 69
  • 3
  • 8
  • 1
    Possible duplicate of [Python Windows Authentication username and password is not working](https://stackoverflow.com/questions/45328654/python-windows-authentication-username-and-password-is-not-working) – undetected Selenium Mar 15 '18 at 06:38
  • if it is a notification.Use this chrome_options.add_argument("--disable-infobars") chrome_options.add_argument("--disable-notifications") driver = webdriver.Chrome(chrome_options=chrome_options) – Sachhya Mar 15 '18 at 10:19

5 Answers5

2

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.

TechnoWolf
  • 35
  • 8
1

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.

talon
  • 69
  • 3
  • 8
1

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.

0

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);
Sandeep Raulo
  • 154
  • 1
  • 5
  • 21
  • Thanks but it didn't work. I added your suggestion to the perf object: `prefs = {'download.default_directory': r"download.default_directory=" + download_folder, 'download.prompt_for_download': False, 'profile.default_content_setting_values.automatic_downloads': 1, 'credentials_enable_service':False, 'profile.password_manager_enabled':False}` – talon Mar 15 '18 at 07:26
0

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.