How to Handle Basic Authentication Pop Up in Selenium

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is Lavinia welcome back to Naveen automation labs surveys today I am going to cover very very small topic but it's very important sometimes that how to handle basic authentication pop-up that you have to sometimes the moment you launch the URL or application URL you are getting one pop-up where you have to enter your username and password I will show you what kind of welcome pop-up and talking about so let's say this is a URL and then the moment you enter this URL you are getting this pop-up right that your connection to this side is not private and you have to enter your username and password like this instead of a proper username password on the webpage you have to enter some username password over here so this thing guys you cannot inspect so if you right click on it there are no inspect options are available right no inspection is available so you cannot inspect you cannot inspect this sign-in or cancel it means you cannot get the ID XPath or class name or name or CSS selector for these things because this is a kind of authentication pop-up is coming from the server and from the server it means in this form this particular side it says not ok you have to enter username password and then you have to click on sign-in button and then you will be authorized then only you will be able to login to the application so I will show you that after login how exactly it looks like so let's see simple it looks like this the moment you you know enter the admin username and password username password is let see for this particular site and if in admin and then you click on sign in then you are coming on this page and okay congratulation you must have the proper credentials or maybe you will be you will be seeing the home page or next page or maybe login page or whatever right so how to handle it so we cannot handle it by using bio text path or by Road ID or something and that case what we have to do along with the URL we have to pass the username and password so it's a very very simple code so let me write let me know enter URL and then I'll show you so let me first go into Google Chrome so this is that launched the Google Chrome that we have to use system property and launching the chromatin and then let me launch the switch the driver the driver driver is equal to new chrome driver and webdriver we have to import like this and then what we have to do raise that very small thing driver dot you get in double quotes what is the URL for this is a URL just copy this URL over here paste it and then what we have to do after HTTP colon double slash before just just the domain name this is the domain name that dot-com domain right before that this domain name what we have to be amplifies the username and password and the username and password for this particular application is admin admin you just need to write admin and admin over here like this with speed me right over there at make a delay and then you click on sign in you will be see that of a yes of regulation you must have the proper attention but how to do that in automation in selenium so you just you write admin is the username colon admin is the password and you just need to write at the rate so username ok username colon password at the rate the URL so the format is like this that's the HTTP colon the whatever it's whatever the user name let's see my user name is Naveen ok : just at the red 1 2 3 at the rate let's see something test.com like this so we have to pass the username and the password so the actual format will be like this your actual username and then your password right whatever the password it is and at the rate test dot form you have to enter right so before you the actual URL being to write simple username : password make sure you are putting : and at the rate on which you are to perform authentication so this is where you are so the moment you see that okay yes that congratulation you must have the proper retention let's see so this is the only line that you have to write now let's see after coming on this page after entering username as password admin admin they are coming on this page and we are going to verify this message that this message is coming correct or not so let's see this message is coming under P right so this is I can take it as a CSS selector and then we will verify that it is coming of not so drag or don't achieve find any mail by dot CSS selector unless it's a selector let's see P and then simple dot you get X method is there and you get touch method will return one string let's see spring page message is equal to this and then I'll print it on the control system dot out dot println simple I'm using page message and then let's run it and we will see it is working a lot so in java application so you see it's launching and now it will not show any username password over simple you can see that congratulations you must have the proper credentials it's coming on this page directly without opening the bottom right and you see it's printing like this but if you don't want to enter this Edwin Edwin let me remove this at minute mean at the rate if you enter the URL like this directly see what happens okay so just a minute it's still launching see and then you will see of try and ring the URL see username and password it is asking now you won't be able to enter the username password over here and you won't be able to click on sign-in button as well so you cannot do that so this is a rule race you have to pass like this okay you have to pass it like this now if you run it again let me close all these bounces and then it's family okay so now with Edwin Edwin we're on it immediately it will be authenticated and automatically it will be logged in because in the you are and we are passing the username and password see so it's not here it's not asking any username and password Potter any authentication proper it's not showing it so this is how whenever you see such kind of thing these simple pass username password like this and that's it and this is a very famous interview question is well that if any authentication pop-up is coming like this how do you handle it so simple you just need to pass like this that's it ok so very simple topic that's what I just wanted to cover I just it just came into my mind and I thought okay I should cover this topic so let me know if you have any issues and if you have any other URL also for similar kind of URL we share with me in the comment section that if your application URL or maybe some public URL is available where these kind of hooks are coming so that I can use those URLs okay then few next sessions in order so thank you so much for watching this video guys and please share with your friends and elites and let me know if you have any issues you can write your comments over there if you have any queries I think it's very simple topic and please share it on social media on LinkedIn or Facebook okay thank you so much guys thanks for watching
Info
Channel: Naveen AutomationLabs
Views: 97,990
Rating: undefined out of 5
Keywords: Authentication in selenium, pop up in selenium, How to Handle Basic Authentication Pop Up in Selenium, selenium, webdriver
Id: fGAggGbvtw4
Channel Id: undefined
Length: 8min 25sec (505 seconds)
Published: Thu Jul 05 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.