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:[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.

2
  • 1
    Possible duplicate of Python Windows Authentication username and password is not working Commented Mar 15, 2018 at 6: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) Commented Mar 15, 2018 at 10:19

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

this is the crazy workaround ever :) ... its worked to me. thank you.
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.

Comments

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.

Comments

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);

1 Comment

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}
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.