6

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

user4157124
  • 2,809
  • 13
  • 27
  • 42
Shoaib Akhtar
  • 1,393
  • 5
  • 17
  • 46

2 Answers2

12

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

Note : Install win32com.client if you have not downloaded. To install win32com.client use below command

pip install pypiwin32
Shoaib Akhtar
  • 1,393
  • 5
  • 17
  • 46
  • Was just curious what could have been the solution through Java? – undetected Selenium Mar 29 '17 at 20:07
  • After getting solution for python selenium, I didn't tried with Java again. But I think using Robot class one can achieve it, go through this post once for detail-http://stackoverflow.com/questions/10395462/handling-browser-authentication-using-selenium – Shoaib Akhtar Mar 30 '17 at 12:36
8

Try following solution and let me know in case of any issues:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys 
import time

driver=webdriver.Firefox()
driver.get('https://www.engprod-charter.net/')
time.sleep(3)
driver.switch_to.alert.send_keys(username + Keys.TAB + password)
time.sleep(3)
driver.switch_to.alert.accept()

Here is the solution for IE on Windows using third-party autoHK lib

Andersson
  • 51,635
  • 17
  • 77
  • 129
  • I am getting this exception. selenium.common.exceptions.NoAlertPresentException: Message: no alert open Actually your solution seems to be for browser based popup, but in my case this is windows based popup – Shoaib Akhtar Nov 18 '16 at 09:07
  • Tried the updated answer, now it shows different exception.. selenium.common.exceptions.TimeoutException: Message: No alert present... tried again after increasing the wait time, but same exception again – Shoaib Akhtar Nov 18 '16 at 09:15
  • Answer updated. I checked it and now it should work :) – Andersson Nov 18 '16 at 10:10
  • 1
    Thanks @Andersson for the quick reply. Your solution works well for Firefox, but it is not working for Chrome and IE. In case of IE both username and password are entered in username field itself and in case of Chrome nothing happens. Any idea what could the issue? – Shoaib Akhtar Nov 18 '16 at 13:23