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:[email protected]/')

Later on I tried to use the same approach in Java

driver.get('https://username:[email protected]/')

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

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Was just curious what could have been the solution through Java?
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-stackoverflow.com/questions/10395462/…
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

4 Comments

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
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
Answer updated. I checked it and now it should work :)
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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.