
Handle Authentication Popup using Selenium Webdriver
Hello, people welcome back to Selenium Tutorial, in this post we will see how to handle windows authentication popup using Selenium webdriver.
Why we are getting Authentication window
Each company having some proxy setting for the specific application so while running script using Selenium you will get this authentication window which asks for Username and password so until we don’t handle this you cannot navigate to parent window.
Example- I have found this URL where actually u can see this pop-up.
https://www.engprod-charter.net/
How to Handle Authentication using Selenium
I think its time to handle this Authentication so now there are two ways for this.
Refer complete video for the same-
First approach- Handle Windows Authentication popup using Selenium Webdriver
You can provide credentials in URL itself it means we will add username and password in URL so while running script it will bypass the same.
Syntax
http://username:password@url
Example :
http://mukeshotwani:password1234@www.xyz.com
Second approach: Handle Windows Authentication popup using Selenium Webdriver
We can use AutoIT again to handle this authentication window for this Please check whether you have AutoIT installed or not. If not then please download from here
1) Open the Url ENGPROD on which the authentication is required and open the AutoIt Window Info tool to get the name of the class and the text of the authentication window.
2) drag the ‘Finder Toolbox to the object in which you are interested and it displays you the information.
3) If you download the full version of Scite4AutoIt3 and look for the Au3Recorder in the Tools menu.
Open the Script Editor window, save the blank file with ‘.au3′ extension and then go to Tools > AU3Recorder or Alt + F6 on AutoIt Script Editor.
A window will open for recording. Let us record the steps to send the username & password to the authentication window, for that please activate the Recorder by Tools >AU3Recorder or Alt + F6 on AutoIt Script Editor.
4) Top left signal says that the recording is on. Now type the username and password and do not use the mouse to click on any field, simply use keyboard’s tab button to do the thing.
5) Once you did with your recording, your code will look like this.
6) Now save the above script, if in case you have not saved the name earlier, please save it in .au3 format.
The next step is to convert it into the .exe format. For that, you need to do a right click on the .au3 file and select “Compile Script“.
Note: Make sure that you select ‘Compile Script’ as per your machine configuration. Select normal version if you are on 32 bits, and select x64 or x86 if you are on 64 bits.
7) Once you did with the compiling, it will create the ‘.exe’ file with the same name under the same folder and that ‘.exe’ the file will be called in the Selenium Test Script by using the following script:
I need to handle this in firefox and also I need to do parallel execution (multi threads)..Is this work in multi threads?No means how to handle in multi threads execution?
Hi Yoga, in Selenium 4 you can do this via CDP and for firefox, you can use RDP. It works in parallel mode too https://learn-automation.com/handle-authentication-pop-up-in-selenium4/
Hi Mukesh,
In our application, lets say “abc.com”, authentication popup comes with different server URL (like “xyz.com”). In that case how can I proceed. With Selenium 4, I even tried, But I am unable to do it. Could you give your thoughts on this..
Thanks,
Pon Surya Prakash I
Hi Surya, in Selenium 4 we have support for authentication. Please check below link https://learn-automation.com/handle-authentication-pop-up-in-selenium4/
Hi Mukesh Sir,
I have created a autoit script for authentication in windows pop up. Selenium code invoke the autoit script using “Runtime.getRuntime().exec(“autoitscript”) ”
But once the script is invoked it keeps on running at the back ground, I.e again authentication pop up is loading.
How to stop it once the autoit script completes its action.
Using Chrome Version 90, Firefox Version 93 and selenium 3.141
AutoIT script
WinActivate(“Mozilla Firefox”)
Send(“Username”)
Send(“{TAB}”)
Send(“Password”)
Send(“{ENTER}”)
Sleep(3000)
Thank you,
Divya
Hi Divya,
Now using Selenium 4 you can bypass this authentication using headers.
Thanks
Mukesh Otwani
suppose my username is abcd and password is abc@1234.
Then my constructed URL should be http://abcd :abc@1234@www.xyz.com/
How this is not working pls suggest.
Hi Poonam,
Encode your @ (which is into password) symbol with %40 and try it
Hi ji,
I saw your selenium Live Project video and i have tried ,one more help we need part 2,part 3, live video …it’s very help for us .so could you pls do it?
Screen shot, Cofing file ,using Xml,TestNG coverd Live video ji Pls .
Hi Muthu,
You can go through this link https://www.youtube.com/watch?v=vFXL4nMWvXI&list=PL6flErFppaj0WwNOMFeXPVlNCDuJyPYFi to find answers of your queries.
Hi Mukesh,
I have tried 1st approach as in my application we are using “domainname/username” and “Password”.So 1st approach did not work for me.Then i tried 2nd approach whatever you mentioned in video But i am not able handle the authentication pop up.please help me on this.
Hi Sadasiba,
Have you tried same with Robot class, if not then please refer this http://learn-automation.com/robot-class-in-selenium-webdriver/
Here using Tab key with Control and V keys, you can achieve your objective.
Hello Mukesh,
https://username:password@URL can handle single authentication pop up, if there are more than one auth pop up, can we construct a URL for the same ? if yes, could you please help me out. I am looking for solution which can handle a auth pop up for both MAC and Windows.
Hi Dhananjay,
Ideally it should be possible but it depends on application authentication behavior.
Hi Mukesh
I am a Mac User and AutoIT does not work with MAC.
Can you pls suggest, I need to automate the same authentication window but using MAC
Hi Sujata,
For MAC i need to check some alternatives. I will update you shortly.
Hi Mukesh,
I am trying to handle Download pop up on my Mac OS system but I don’t know which tool to use coz Auto IT doesn’t work with MacOS .I already know how to work with Robot API,but i want to know some AutoIT equivalent tool for Mac OS and also how to work on the tool.Can you please help me here. Thanks 🙂
Hi Priyanka,
Sikuli works for MAC as well.
http://learn-automation.com/integrate-sikuli-with-selenium-webdriver/
Hi,
Through Auto It Script “Ok” click is not happening , instead focus remaining on “popup” it self.
Hi Kibs,
Try to add wait before click.
Hello Mukesh,
I am new in Selenium Web Driver,
can you tell me how to handle Dynamic web tables using POM.
I have Web Table n number of rows and n number of columns ,But i need select a particular based as column 1 and i need to click columns 5.
Hi Ram,
Below article will help you http://learn-automation.com/handle-calender-in-selenium-webdriver/
HI this is the very good way to handle the Authentication Alert , it was working fine for me but now i am getting below error about this please help:
org.openqa.selenium.UnhandledAlertException: Modal dialog present:
Build info: version: ‘2.44.0’, revision: ’76d78cf’, time: ‘2014-10-23 20:03:00’
System info: host: ‘DS-6CF049FD194D’, ip: ‘10.144.49.187’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.8.0_77’
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:12885/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 60008b87-c5f2-4695-b6d9-92bb0b26e7ca
Hi Madhur,
Can u try the same with robot class ?
Hi Mukesh,
I tried the method you specified. I am working with selenium (Eclipse Juno) and trying to write the script for auto login on the pop up just like above but in chrome. But it is not working for me. I have done exactly what you have done. Tried putting the path after and before I am opening the browser but no change. It is not filling the field with the required credentials.
I also tried looking for the Auto Recorder but I could not find it at all.
Could you please help,
Hey Abhishek,
Use robot class or Sikuli for chrome if autoIT is not working.
Even i tried the same stuff but i am unable to see any progress nothing turned out actually.
Can you tell me why it is not working
Hi Amit,
Try robot class of Java it works for me always.
We are in the situation that we don’t know when the authentication proxy pop-up shows up but we need to close it by clicking on cancel/ok-button. At the same time, we can not call AutoIt script for every get method of firefox driver because we have 100 of test cases. What we are expecting is, something like we need to run AutoIt script when selenium automation starts and the script should be always running and if pop up rise then the script has to close it and it has to go back running status instead stop. I am waiting for answer,as you mentioned you would post answer for this
Hi Selva,
If you can find the pattern when it appears then Selenium can help.
How to do this for Opera Brower
Hi Rupesh,
Sorry but I have never tried with Opera browser.
Hi Mukesh,
Thanks for all your videos and tutorials it was really helpful, i just implemented the auto it script authentication window as per the tutorial it was worked well for me, same like akashsuthwal question i want to use multiple times in my script still there is no answer i have found please help me to proceed further
Thanks advance.
Arun
Hi Arun,
This will help
Hi Mukesh , this is awesome blog, can u plz share the way to parameterize the input for Auto IT tool so that it accepts while Authenticating the pop up, you told you will post it in a weeks time while replying to Akash, i am eagerly waiting 4 the same.
hi Vishy,
This will help
HI Mukesh,
Thank you for your effort to make this happen. I have a task to handle this authentication pop up using selenium webdriver not just in windows but in Linux and mac os. I don’t think AutoIt will fit for the rest but windows. Could you guide me with some help so that I could complete. I got another option rather than this which is by using Sikuli IDE. I am completely new to this and I have already crossed the deadline.
Could you please help me achieve it.
Looking forward to hear from you.
Thanks
Abhi
HI Abhilash,
is it fixed? Sorry I was on long vacations.
i want to login with 20-30 different user’s credentials , so for that do i have to write 20-30 autoit scripts ???
is there any option that Autoit script took parameters from an excel file ?
Hi Akash,
It’s very interesting part and yes it is possible with small piece of code.
I will upload the code by this weekend.
The autoIT code that I wrote doesn’t work in Selenium. It doesn’t throw any error either. How to ensure that
Hi Divya,
Sorry for late reply. I am using this code and its working fine in my machine. Can you please share ur script so that I can check the exact issue?
Same issue with me also, I have used below script in Autoit,but not taking passed values in user name and password fields and also its not displaying any error in console.
WinWaitActive(“Authentication Required”)
Send(“uday”)
Send(“{TAB}”)
send(“sarikonda”)
Send(“{ENTER}”)
and passing below mentioned code in class.
Runtime.getRuntime().exec(“C:\\Users\\UDAY\\Desktop\\autoit.exe”);
can you please help me..
together a head,
Uday Reddy.S
Hi Uday,
Kindly use some sleep between commands.
Hi Mukesh,
This worked for me. Thanks a ton mate.
the script did not work for me!!! any other solutions?
Hi Swamy,
this should work.. Can u share autoit scipt which u have written?
can you use sikuli instead of auto it for Authentication handling?
Hi Sooraj,
Yes you can use.
hi,
I am new in Selenium Webdriver.. and i was just searching solution for authentication pop up.. you explained very well.. thanks.
Hi Manjushri,
Glad to know that it helped you 🙂 Please check other section of Selenium and let me know if you are finding any issue while automating scripts.
Thanks
Mukesh
Hey! Someone in my Facebook group shared this website
with us so I came to give it a look. I’m definitely loving
the information. I’m book-marking and will be tweeting this
to my followers! Excellent blog and superb style and design.
Hi,
Glad to hear that you liked my blog, it gives me motivation to move forward. Thanks for sharing with your followers.
I have couple of post Pipelined will update soon. Stay tuned 🙂
Thanks
Mukesh