Shoaib Akhtar Shoaib Akhtar - 16 days ago 11
Java Question

How to handle windows authentication popup in selenium using python(plus java)

enter image description here

I tried the below code, but it didn't work for me

from selenium import webdriver
driver=webdriver.Chrome('D:/BrowsersDriver/chromedriver.exe')
driver.get('https://username:password@www.engprod-charter.net/')


Later on I tried to use the same approach in Java


driver.get('https://username:password@www.engprod-charter.net/')


But unfortunately it didn't work for me in any browser. Am I missing something here?

Then I tried with AutoIT in Java

Runtime.getRuntime().exec("D:\\FirefoxWindowAuthentication.exe");
driver.get("https://www.engprod-charter.net/")


It works well in Firefox & IE, but didn't work for Chrome. Is there any way that at-least I can achieve this in selenium using python & what I am missing in case of Java. Please suggest me any solution, tried a lot

Answer

I got this solution which is working well for all three browser(Firefox, Chrome and IE).

from selenium import webdriver
import time
import win32com.client

driver=webdriver.Firefox()
driver.maximize_window()
driver.get('https://www.engprod-charter.net/')
shell = win32com.client.Dispatch("WScript.Shell")   
shell.Sendkeys("username")  
time.sleep(2)
shell.Sendkeys("{TAB}")
time.sleep(2)
shell.Sendkeys("password") 
time.sleep(2)
shell.Sendkeys("{ENTER}")
time.sleep(2)
driver.quit()