How to handle Permission Pop-ups using Selenium WebDriver | Selenium |

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone i am yada karedi and welcome to my channel hvr tutorials in this video we are going to look at one of the important topic that is how to handle permission popups using selenium webdriver so what are these permission popups actually i mean we never heard of these things right so we know the pop-ups we know the alerts we know the prompts okay so we never heard of this permission pop-ups what exactly this permission pop-ups are actually okay so let's see okay so before going further first let's see how this permission pop-ups are actually looking like okay so let me open the chrome so here i have some websites so let me copy the first website go to that website so this is a cleartrip.com website okay so now you see we have a pop-up here right so it says show notifications hello or block okay so it has two options and this pop-up is there right so whenever i open this website i'm getting this pop-up so what i need to do i need to click on allo or block or i don't want to get this one completely okay i want to just click on cancel okay so i don't want to see the pop-up itself so that is what our requirement right so like this there are so many permission pop-ups okay so if you see okay first let me show you all the pop-ups then we will discuss about what are the permission pop-ups and everything okay so here when i click on this one here again it says show notifications allo or block okay so the first two are actually based on the notifications only so let's go to the third one so here it says know your location okay so it is a location based permission pop-up not a notification based one okay and like that we have two more so when i open this website so i want to test my microphone okay so i click on this test my mic here it is asking the permission okay use your microphone so for the microphone also it is asking the permission allow our block okay so it's a microphone based permission pop-up and the last one is camera based permission pop-up okay so i want to test my camera so my web camera i want to test so when you click on test my cam here you can see use your camera allo or block so it's a camera based permission pop-up so all these pop-ups we call it as a permission based pop-ups okay so these pop-ups will have two options those are allo and block and every pop-up will have the same ui now you see here in all the pop-ups the ui is same only okay the only thing that is actually changing here is the website name and the permission type here the camera is there and here microphone here it's a location here it is notifications okay so the permission type is actually getting changed but the options and the ui is same only right so how do we actually handle this so is it a browser-based pop-up or is it a application based pop-up so let's find out that also okay so let me open the developer tools so first let me inspect this one okay so i'm not able to inspect see my mouse is on this one only on this pop-up only but it is not highlighting anything right so it is going to the application so that means it is actually a browser-based pop-up okay even though this pop-up is actually coming from the application the pop-up is actually displayed by the browser okay please understand the statement carefully the pop-up is actually coming from the application only okay so this application is having show notifications pop-up like that this application is having know your location pop-up okay so the pop-up is actually coming from the application only but it is displayed by the browser not by the application okay it is displayed by the browser it is not a html based pop-up okay it's a browser-based pop-up that you need to understand okay so how you will handle this browser browser-based pop-up so you might say like we have already handled alerts okay so the alerts and these pop-ups are actually completely different okay so the alerts are completely different and these pop-ups are completely different okay so that is why we need to handle these pop-ups in a different manner okay so how we will actually handle i mean how we can handle these pop-ups basically so what are the options you can do one thing is we can click on allo and we can click on block or we can completely click on this cancel okay that means we don't want to see the pop-up itself okay we don't want to see the pop-up in our application whenever i open the application i don't want to see the pop-up so i don't have any requirement so i don't want to see the up i mean pop-up okay so that is one option right so in some scenarios i have a requirement to click on allo or block so those are the different options i mean those are the different requirements basically right so in this video we will see both the options how we can completely remove the pop-ups from the application and we will also see how we can click on the allo button and block button also when in this pop-up okay so here this video is going to be a little lengthy video guys because i need to explain everything in detail right so how we can close the pop-up completely i mean how we can remove the pop-up completely and how we can click on the buttons completely okay so i need to explain very clearly otherwise you will not understand anything okay so if you have any urgency so that you can just check out the video i mean the program link so i'm going to attach the program link in the description below okay so you can directly go to the program that program will be available in my github repository you can directly go to the program and you can get the code okay so if you don't have any adjacent and if you want to understand the concept right please watch the video completely okay so it is going to be a little lengthy video but please have some patience and watch the video completely okay so first let me open the eclipse so first i want to go to any website right so driver dot get so first i will take this clear trip okay so i don't want to see the pop-up itself so first we will see that part okay so this is a notification pop-up so any pop-up is fine okay so here i'll navigate to this website so first before handling it let me execute this okay so i am not handling anything in the automation and i want to see whether the pop-up is actually coming in the automation browser or not now you see the pop-up is actually coming in the automation browser right so that means we have to handle it okay so how do we handle it so if you want to perform any operations on the browser okay not on the application i mean application you want to perform the operations on the browser then how you will perform we have to make the changes to the browser itself right so these are the pop-ups that are coming from the browser so we need to make the changes to the browser only so how do you make the changes we have capabilities right so desired capabilities are options so we have these two options okay so we can use either desired capabilities or options and make the changes to the browser okay so the desired capabilities is actually coming from the selenium webdriver and this chrome i mean options are coming from the individual browsers okay so for chrome we have chrome options for firefox we have firefox options for edge we have edge options like that okay so here i'm using the chrome browser so i need to use the chrome options here okay so we don't have any common thing here desired capabilities why because the desired capabilities coming from the selenium webdriver so this is not coming from the selenium webdriver right so cylinder webdriver handles only the web-based applications not this browser popups actually okay so that is why it is not available in the desired capabilities okay so it is available under chrome options only okay so i'm going to create the instance for chrome options chrome options is one class okay so i'll name this one as options new chrome options you all know how to create the object right so this is how we will basically create the object so now i have the instance okay so i will use this one and in this options right there are different things you can set the preferences you can add the arguments okay so there are many things basically you can perform in different different types you can add the capability directly also or okay so here i'm going to add the arguments okay so add arguments so for add arguments there are two methods one is list of strings and another one is only string okay so if you want to add only a single argument you can choose the second one okay so here i'm going to pass the value so it is not going to be a two values guys okay it's not like a key and value pay it's going to be only value okay there will not be any key or anything okay so what is the argument so here what i want to actually disable i want to disable the notifications pop-up right so further i need to write disable hyphen notifications okay so let me check the spelling yeah the spelling is correct so disable notifications so i want to disable the notifications okay so now i need to pass this options class to this chrome driver constructor right otherwise even though you have created this chrome options class instance and added all the i mean properties or arguments or something that will not work okay until and unless you pass this options to the chrome driver constructor these options will not work okay so i am passing the options to the constructor here so now let me run the program again okay so this time i should not get the pop-up right so let's see so the browser window is opened so it is navigating the application now you see the loading is completed and we did not get any pop-up here right that means that pop-up is completely gone okay so it is completely removed from the application itself now so it is not even asking us okay so that is about this disabled notifications so in the similar way if you want to disable the location based so we have the location based also right so this is a location based pop-up okay so if you get this one you can simply change the argument here okay so this argument is for the notifications so i will show the argument so here we don't want to disable the notifications we want to disable the location location in the sense geolocation basically right so this is the argument that you need to pass okay so if you want to disable the location based permission pop-up this is the argument okay so now we have seen how to disable the pop-ups right the permission pop-ups so let me just comment this so in the similar way guys okay in the similar way if you want to remove this one there is another one okay so the same way the argument is disable media stream okay so media iphone stream so if you want to disable the microphone or camera you can use this one okay so let me comment this one also so now we have seen how to remove the pop-up completely right so now we will see how to click on allow and block okay so those options so for every pop-up you will have three options basically okay so let me just click on allow so that i can show you so here you can see we have three options the first is ask or default i mean ask that is the default one and the second one is allo and the third one is block okay so if i select this ask right so every time when i reload this page every time it will ask okay so for this test mic right i need to click on this one see now it is asking okay so here we have three options right so these three options we will see how to handle okay so here i have one diagram so you need to carefully understand this diagram okay so if you want to handle the options right if you want to click on allo or block you need to carefully handle this i mean you need to carefully understand this diagram basically okay so basically we have the chrome options right so in the chrome options so here if you want to disable right we have used arguments okay so in the similar way in the chrome options we will have so many things okay like arguments we will have preferences we will have profile okay so there will be so many things so in the similar way here if you observe this one so in the chrome options we have the preferences okay so under the preferences we have profile and some other preferences under the profile we have different different types of profile okay so this is the profile that we are going to make the changes to so if you want to perform any click operations right on those permission pop-ups so this is the profile basically okay so these for these three are actually key value based things okay not like arguments arguments is having only one value right these are actually key value based things okay so if you don't understand now while writing the program you will easily understand okay so first we will handle the notifications one so we have to create one hash map so it's a key value pay right so for key value pair we are going to go with the hashmap okay so first let me create the hashmap and slowly i will explain you okay so let me just create the hashmap first okay so i'm going to create the map here hashmap so the first value is going to be a string okay and the next value is going to be an integer okay so these are the actually settings guys okay so you can say this is like a argument or something okay so notifications geolocation and media stream so under the media stream only we have mic and the camera also okay so if you want to click on anything right we have to set the values like this 0 1 2 okay 0 means ask 1 means allo 2 means block so 0 1 2 are the integer values right so you can take integer or you can directly take the object also okay so the superclass of all the classes is object so i'm going with integer okay i need to name the map so what is the map so many default content settings so this is a content right so i will name the my map as content settings okay content settings so i need to create the instance here and next so this content settings are going to store in profile okay profile is again based on the key value only okay so again i'm going to create one map or before that first let's add the content settings okay so then we will see so content settings so how do you add the values into the map we will use put method right put is the method we are going to use so input first the one first one is key and the second one is value okay so here the key is nothing but this one okay notifications are geo location or media stream so let me type that notifications okay then the value will be zero or one or two okay if you want to allow it will be one okay so i will allow that by default okay so this is the one so i want to add this content settings into another map that map is nothing but the profile okay so i want to add these complete content settings into the profile right so let me make one more map here so this map is also having key and value right the key will be this one content settings i mean it will be a string value only and the value will be the complete content settings object itself okay so here i will write string so you can directly write map here or you can directly write the object also here so object looks like easy one right so you don't have to worry much so where we are adding this content settings we are adding that one under profile okay so i will write profile then i need to create the instance okay so now the profile instance is also created so let me create this one also preferences also okay so hashmap string so the key is actually string only and the value is going to be profile the profile will be stored under the preferences okay so again i will mention object instead of mentioning this hashmap and all i'll mention it as object okay so what is this preferences right so new hash map okay so now all the three maps are created and the super one is chrome options so that instance is already created here right so let me take this here and put it here okay so i'm going to put it here so now the content settings are created okay so i want to add these content settings under profile so how do i add profile is also again a map only okay profile dot port so the key is this one okay you need to write this one managed default content settings so let me write that so i have added the key here right so the value will be content settings okay so let me add that one here and close this one so now the profile is also created okay the profile needs to go into the preferences right so let me add the profile into preferences preferences dot put so the profile is profile only the key is also profile only okay next the value will be this profile object okay now this preferences needs to go into the options okay so how it will go options dot options is a instance right not like a hash map or something so you cannot use put okay so which method we need to use here we have so many methods right our add arguments add capabilities okay so we have set capability so which one we need to use so we need to use set experimental option okay so this is the thing that we are going to use okay so here the first value is string and the second value is going to be object okay so the key is string okay so what is the key preferences okay so preps and the value will be this object okay so if you understand for one thing right you will understand for all the permission based pop-ups so for everything it is same only okay only this content name will be changed otherwise everything will be same only okay so now it is done right so we have to add these options under the chrome driver constructor so that is already completed right so now let me execute this so before executing that one first let me put this one as zero so that first time it will ask okay the pop-up should be coming right so i want to see the pop-up then we will change each option and we will see how it is actually clicking i mean you cannot see the click operation okay so from the ui you cannot see the click operation now you see the pop-up is coming right so we have given zero option that means always ask okay so let me close that so i will change this value to one okay so now let me run this so the browser window is open and we did not get any pop-up i said it is going to click on allo right so it is not going to show any pop-up and click on the allo okay by default when the browser is actually opening it will set that setting so where you can see that setting so just click on this lock button okay here you can see notifications this is set to the allo okay followed by your administrator who is administrator this selenium webdriver script is the administrator right so from here we have set it to allow okay so let's change to two what is two two means block okay so let me close this browser i want to execute again so i am setting it to block okay so now also it is not going to show any pop-up because internally it is going to set the preference right so now if you again see here it says notifications block blocked by your administrator who is the administrator again the selenium web driver script only okay so if you change the value here that value is going to be reflected here okay so it is not going to show the pop-up and click on the allow button or click on the i mean block button or something okay by default whenever this application is loaded in the browser it will set so that is how we are going to click on that buttons okay so in the similar way now we have seen for the location i mean notifications right so i want to see for the other one so what is the other one location okay so let's use this website i will just comment this and i will write again so i want to i mean test all the things right so for this one i'm going to first comment this and the content will be different right so as i said the content will be different so what is the content here for location geo location is the content okay so let me change this geo location okay so by default i am setting it to zero let's see what happens so the browser window is open now you see the pop-up is coming right the location pop-up is coming that means it is set to zero okay so now let's change the value to one so i want to allow the value okay i want to allow the location basically this is very simple guys so if you understand for one thing right all the other pop-ups are easy okay so here you can see the website is loaded and it did not pop up anything okay and here you can see the longitude and latitude is also displayed okay that means the location is actually allowed okay so let's see location hello followed by your administrator okay so i want to block that location how do i do that it's just changing the option right so let me run this again so now i am not getting any location here why because i have blocked the location okay the location access i have blocked so if you open this one you can see the location is blocked by administrator okay so that is why it is not showing any longitude and latitude so this is how you need to click on the geolocation pop-up and what else is spending the microphone and camera right so let's look at the microphone one so for microphone and camera the option is on i mean the content is only one that is media underscore stream okay so here let me add that oh sorry this is the website right so just comment this driver.get the url is this one okay and the key is media underscore stream okay so i need to write that media underscore stream okay so again the values are same guys okay the values are same so directly i'm going to show you only one here anyway the values are same right 0 1 2 all the pop-ups are having the same value so i want to just click on one okay so here you need to observe one more thing guys okay so what is that so when i open this website by default this pop-up will not be coming right so i need to click on something so what is that so i open this website i need to wait for some time then i need to click on test my mic button okay so let me inspect this button first so this button has one id but this button is being displayed after some time only right so i need to give some thread dot sleep here so i'll give some six seconds okay then i need to click on that button driver dot find element we have the id okay by id dot click so i need to throw the exception okay so let me choose the super class exception so after clicking on this that pop-up will be coming but here i'm setting it to already alone so the pop-up should not come okay so let's run this mic test dot com is opened and the button is knotted displayed okay so now the button is displayed and you can see starting your microphone please wait that means we have already allowed the microphone right so that is why it is testing the microphone already okay so if you go here you can see camera and microphone both are actually allowed okay hello alone so as i said if you set one thing by default it will set to two things okay and the key is also only one right media stream means it will be applicable for the mic and camera also okay the camera is also allowed and microphone is also allowed okay i'm talking here now you can see it is actually rising okay so you can observe that right that means the mic is actually working okay so the next one is the camera so for camera also we need to click on the camera i mean test my camera right so first this is the website so i need to change the website so the website is this one so here also after some time this button will be displayed so let me inspect the button so this button also has one id so i'm going to simply change the id only here okay the timing i'm going to keep it like this and this is also not going to change okay for camera also this is the thing okay so let me run this so now also i am giving the option as one by default i am allowing it okay so you can i mean you can test the other options guys zero and two so while you are practicing you can test that okay now it is actually clicking on that you can see waiting for permission and starting your webcam actually in my laptop i have another switch to switch off the camera okay so that is why nothing is visible here okay but you can see here the camera and microphone both are allowed okay so that is how you need to set the options guys okay so that is how we basically perform the operations on the permission based pop-ups okay so you understood right so what is a permission based pop-up and how you need to handle those pop-ups okay so we can handle the permission based pop-ups in three ways the first one is we can directly remove the pop-up okay and the second one is we can click on allo button and the third one is we can click on block button okay so those are the options guys so this is how we are going to handle permission based pop-ups so now you got the idea right what exactly the permission based pop-up is and how you need to handle okay so now if you see the diagram it will be easy to understand okay so we have chrome options inside the chrome options we have preferences inside the preferences we have profile inside the profile we have these keys okay so if you want to get other things like this you can go to this website okay i'm going to show you that one as well so just go to this website okay so this is coming from the google only so if you go all the keys are present here okay so all the content keys okay so if you come down here you can see preferences that are exclusively used to store managed values for default content settings here cookies images javascript plugins pop-ups geolocation notification media stream so we have seen these three right there are some other different kind of pop-ups so for those pop-ups you can use this one so if you want to allow or i mean although the plugins you can use this one okay so sometimes javascript also needs to be allowed okay so there you need to handle this javascript images and cookies as well so here the cookies are there right so like this whether you want to allow the cookies or not so that also can be handled using this one only okay all you need to do is add this content key okay add this content key here and use the values as zero one two that's it okay you will get to know how those things are actually working so i'm going to leave all these links in my description box below okay so you can check these websites so if you have any other website that is absolutely fine so if you don't have any website just for the reference like for the practice i'm going to leave all these links in the description box below so you can check each and everything here okay so just check this one also there are other things also so just take all these other things also okay so already this video is lengthy thank you for watching with patience so that is for this video guys if you have any questions or if you have any feedback please let me know in the comment section below and don't forget to like and share this video with your friends thank you for watching bye bye
Info
Channel: H Y R Tutorials
Views: 44,058
Rating: undefined out of 5
Keywords: hyr tutorials, h y r tutorials, How to handle Permission Pop-ups using Selenium WebDriver, permission popup, popup selenium, popup in selenium webdriver, popup handling in selenium, know your location, show notifications, use your camera, use your microphone, selenium notification popup, selenium location popup, disable notifications, disable geolocation, disable location, chromeoptions in selenium, selenium webdriver, selenium webdriver tutorial, webdriver, selenium, java, popup
Id: deKXbbIHD4w
Channel Id: undefined
Length: 29min 5sec (1745 seconds)
Published: Tue Mar 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.