How to handle Dynamic dropdown in a Generic way Selenium Automation Testing Lecture-33

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome back to my youtube channel in today's lecture we will understand how to automate a dynamic drop down in a generic way till now we have understood the concept to automate a dynamic drop down according to the criteria given in a particular site but now in this lecture i will tell you how to automate a dynamic drop down in a generic way as i as i have already told you for the generic date figure similarly we will understand the concept of generic dynamic drop down so let us begin our lecture for this i have taken a site of make my trip where i will tell how to create or how to automate a dynamic drop down in a generic way you can see that here a dynamic drop down is present in which we will just click on this particular div inside div we will type whatever city we want so if we want a city named as kolkata we will just type kolkata inside this particular text box and before typing this thing that is kolkata inside this input text box we will just click on what we will click on this div so we have understood the criteria that is we have to click on the a particular div so let us right click on this particular div inspect we will inspect it and click on particular div this one you can see that label for from city this one is the thing and we will automate it or create a locator using parent child traverse relationship which i have already told you and in this lecture i am not focusing on to create the locator i have already created the locator and i will use it and i will just focus on to create a generic dynamic drop down picker so let us focus on our concept i have already created the locator you can see that this one is the locator you can also cross verify it whether the locator is correct or not just copy it ctrl c here ctrl f and just you have to paste it ctrl f you can see that aft after clicking on this this particular thing you can see that whenever we we will type it here and click on enter you can see that one of one one of one it is showing again you can cross verify it one of one and i have already told you this one is the locator and for this i have used the concept of parent child traverse relationship in which i have used this class slash label whatever i have told earlier so we will use this locator technique for this we will just paste it here inside the eclipse we will use in we will use it later on you can see that already pasted here again similarly what is the next concept here we just have after clicking on this particular thing we have to find out the locator of this input text box for this right click on in this one inspect it you can see this this is the input and for this again you will use the parent child traverse relationship in which you will start from this div and this one is the child of this particular div again this one input so your locators will should look like div class equal to this one slash div and then slash input already we have created the locator and you can cross verify it also just copy this one and we will cross verify it because we do not want to waste to create the locator locator and waste our time we are just focusing on to create the generic dynamic dynamic drop down you can see that just ctrl a ctrl v you can see that we have already found the locator that is what what i have already told you i am just using this class slash div slash input not more than that you can see that slash div slash input and the name of this particular class what is the name of this particular class somewhat plug-in you can you can see that i am just using this one this class i am using you can see that hsfw auto complete pop-up auto-suggestive plug-in you can see that i am just using this so i will use this locator and paste it in our eclipse we will use it in our future you can see that and just paste it here now already we have got these two locators this the first one and then the input text box inside this you have to write anything whatever city you want suppose that you want kolkata you will just write kolkata i think you got the concept up to this one after typing this one you have to to find this li or whatever is it paragraph p whatever is it you have to find the locator of this one how you will be able to find it just click on this you can see that p class equal to this one is for for a particular particular thing that is kolkata similarly durgapur whatever you will type accordingly the things will come here if you type patna here just you can see that but after typing patna after typing patna you will be able to see patna bhuvaneshwar all these things all the cities accordingly i think you got the concept you just have to type whatever city you want to uh to take a flight you have to just type the name of that city afterwards you will get these things you have to find the locator of that particular thing how will be able to find out using the p and the class this one only you have to do this again i have already found out the locator this one you you can just cross verify it ctrl c and paste it here ctrl a you will do and ctrl v you can see that after typing anything that the cities which will be will be seen here will be find out by using this locator so we will just use this locator and paste it in our eclipse to use it in future just we pasted it now already we have got the locators for the thing which we want to do you just have to use the concept of generic dynamic drop down which is our motto so just you have to create the things and you have to use the concept to make it in generic way so you will just type driver dot find element and what whatever locator is it find element you have to type just type just type find element driver dot find element and inside this you have to give by dot whatever is it is it it is x path you have to give x path driver dot by dot x path inside this by dot x path you have to pass the locator you have already created this is for the div control x you will do and paste it here ctrl x now what you want to do you have to click on that particular thing because after clicking the input text box will come so you just have to click on this one dot click after this again you have to use this line ctrl c paste it here and inside this just change the locator this one is control this one control x here just paste it here ctrl v and instead of dot click you have to send keys whatever city you want to type you have to just do this send keys inside it type whatever city you want to suppose that you want city kolkata just type kolkata here just remove it now you have already inserted the city name which you want suppose kolkata you want you will type kolkata after which you have to the you have to click this p already i have told you you have to click whatever city is present here accordingly you have to click but you want to click on patna or kolkata whatever suppose you want to v to book a flight from kolkata after typing kolkata these two cities are coming but you want to click on kolkata so you have to find this kolkata thing and using the locator that one which we have already created we will find out kolkata we can't click on durgapur so using the using the generic way we will be able to click on this kolkata let us see how we'll be able to do so we will use this particular thing and use the concept of arraylist here why we will use the concept of arrest because it is showing one of three one of two here one of two it is more than one so we will use the concept of list here we can't use the concept of wave element here so we will just write the concept of list which we have already used for generic date picker as you have already watched that particular lecture if you haven't watched that lecture i will provide the link of generic date picker also you just have to write wave control space you will do wave element after this give a name suppose that this is for dynamic list dynamic drop down so we will name it as dynamic list equal to you have to just write driver dot find elements driver dot find elements inside this you have to write by dot css selector because we are using css selector technique inside this one just pass this thing ctrl x and paste it here what you want to do after this you want to click on that particular thing dot no no no this this is the thing we just want to create the list so we will just paste the locator here and the dynamic list named as this list will be created using this list we will be able to automate that dynamic drop down in generic way how we will do we will do this just focus on this for this we will use the concept of for loop here how we will do just focus on it you have to write for int i equal to 0 semicolon i less than dynamic list if you have watched the lecture of generic generic date picker you will be able to understand it more properly if you haven't watched you can watch it i less than dynamic list dot size you just have to write dynamic list dot size semicolon i plus plus and inside this one give curly braces and write string text string text equal to equal to dynamic list dynamic list dot get this one i think spelling is not correct ctrl c ctrl v dot dot get this one i dot get text what does this line means it is telling that you have to find the text of each element present in this list as i have already created a list of wave elements means here there are two elements present what are these these are wave elements so we will put these wave elements inside the list and here i am telling inside this text string put the text of all these wave elements means put the text of these two wave elements here and what are the text of these two web elements the first one is kolkata india and the second one is durga for india so i'm just getting the text of each wave element after this step what you have to do after it you you have you have got the text just print it out what you are getting see so you will do control space inside this you just have to write text age text is plus what what what you will type here this text just write text here text now after this you have to give a condition for making it a generic dynamic drop down how we will be able to do so just you have to write if text dot contains you will use why you can use equals ignore case also which you we have already used in generic date picker but what will happen using equilo equal ignore case if you use equal ignore case then you have to type the entire text of the particular city suppose that the particular text of this city is kolkata india so you have to type kolkata india here you have to type kolkata india properly you have to type you can't type only kolkata i think you got the concept here you can see that mumbai india is the the content of this particular thing means you have to type mumbai india entirely but if we will use contains then then a part of these things also can be written what does i mean i mean to say that in this mumbai india if you type only mumbai or also then the contents will work but if we will use equal ignore case then you have to type this whole content that is mumbai comma india so we will use here contents means mumbai is mumbai is con contained inside what mumbai india so we will use contents here text dot contents and inside it we will type whatever city you want to get suppose that we have already given kolkata here so we want kolkata we will just write kolkata here again we will verify it whether the the spelling of kolkata is correct or not in this particular thing you can see that after typing kolkata what is coming you can verify it you can see that capital kolkata is present so you have to write capital k kolkata so we have just written capital k o l kolkata so after this you have to give this thing what you will give you will just write dynamic list dot i think we have given the wrong spelling here just this one here dot get this one that is i you will give and what you will do you will use dot click here dot click and after this you have to use break which i have already told you told you in the generic date picker code that is if we will not give the break here then after clicking this kolkata also it will try to find the kolkata means if you click on this kolkata it will try to find the kolkata thing but now after clicking on it where is the kolkata present so you have to break the condition here so you have to give the break particular thing this this is given so after writing this code just check it whether our code is correct or not so we will just save it and try to run this program if this program runs successfully then this is the code of generic dynamic drop down so we will just click run as java application we will just use this after this one if our programs program is correct then we have successfully created the code for generic dynamic drop down you can see that after this one it should click on that particular div kolkata is written there after it writing kolkata it should click on the kolkata thing if our code is correct if if something is wrong we will find it out what is the wrong thing here you can see that mumbai delhi bangkok bangalore pune hyderabad all these things we got in the text but we haven't got the text kolkata there what is the problem you have to find it out it is it is telling that still element reference element is not attached to the page element means it is not getting the kolkata thing so you have to see the console here after what after seeing the context here you can see that the text is mumbai we are getting delhi we are getting bangkok we are getting even bangalore pune and hyderabad we are getting but we are not getting kolkata why we just have to focus on focus on it send keys we have done kolkata kolkata after clicking yeah i got the thing you just have to give a sleep thing here why after the successful run of this program i will tell you why i am giving sleep here i will give three seconds of sleep here space control space again maximize it yeah you got that after this one again you will control f11 after clicking on it you can see that i think it should work after giving the the sleep here it is opening the make my trip make my trip it opened it will try to click on this particular div it will type kolkata there after that you you got that you can see that it has clicked on a particular kolkata thing why we required to give sleep here because after clicking on that particular div means this one after clicking on this particular div and typing it it is typing something means it is typing kolkata here but if you will not give time here it will not get these two things because whenever you are typing this one you can see that different different cities are are being seen here but kolkata is not being seen so for typing it it should require some time and we are giving three seconds after clicking this thing and writing these things you can see that after after clicking on that particular div and before typing kolkata there you are giving three seconds to type it properly and so you will be able to click on kolkata that you have already seen that i think using this code you can create a generic dynamic drop down so i think you got the concept where we use the concept which we have already used for creating a dynamic date sorry generic date picker so i think you got the concept if you liked my content please like the video share it to dear ones and kindly subscribe my channel
Info
Channel: gaurav kumar gupta
Views: 4,233
Rating: undefined out of 5
Keywords:
Id: 4uH5EYYIZ4Y
Channel Id: undefined
Length: 22min 49sec (1369 seconds)
Published: Sun Jan 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.