Speaker A
So in today's session, we'll see how we can handle drop downs. Drop downs, or we can say drop down box, right? So dropdown is a most important topic. So let us see because there are different types of drop downs, we will handle them in different ways. Okay? Some predefined methods are also there, and without predefined methods also we can handle the drop down. So majorly, there are three kinds of drop downs we can see on our applications. So the first type of dropdown is normal selected drop down, and Bootstrap drop down, and then hidden drop down. So these are the three kinds of drop downs we can see normally in our applications. So if you have a selected dropdown, this is very easy to handle because we have some built-in methods available. So we can easily handle those selected drop downs. So these are the default drop downs, and most of the latest type of applications nowadays have Bootstrap dropdowns and hidden dropdowns. So these are the two latest technologies, but the old selected dropdown is an old one, and sometimes you can see select drop downs. Sometimes most of the times you can see Bootstrap and hidden drop downs. And different approaches are there to handle these dropdowns. We'll see one by one. So first, let us start with the select drop down. So how we can handle the selected drop down. And one more thing, in these three dropdowns, only the first type of drop down is having select tag. If you inspect that drop down element in HTML, you can see select tag. Okay? And then you can confirm that is a selected drop down. If you see, if you're able to see select tag in your HTML, you can confirm that is a selected type of dropdown. And if you don't see select tag, sometimes you can see div tag. Okay? And other than div tag, sometimes you can see button tag or some other tag. So those all come under Bootstrap or hidden drop down. Okay? If you're able to see select tag in HTML, that comes under the select drop down. And other than select, if you see any other type of tags, that comes under Bootstrap or hidden drop down. Okay? So I'll show you a sample example how we can handle these three types of drop down. First, let us start with the select type of drop down, select drop down. So I'll show you a sample example. So let's go to test automation practice, and here if you look at this, there is a drop down called country, right? There are multiple options are there in this drop down. So if you inspect this element, you can see select tag here, and if you expand the select tag, you can see multiple option tags. So every option in this dropdown is having a separate tag. Okay? So how many options are there in the dropdown? There you can see those many number of options present inside the select tag. So these are all options are child tags of select tag. Okay? And this is called select drop down. So as you can see select tag here in HTML, that is called select dropdown. Okay? Now the drop down element itself is one web element, and inside this there are multiple options. Every option is a web element. So that means one web element contains some more web elements. So the drop down itself is one web element, and inside this, each and every option is also a web element. Every option is a web element, but these are all child elements of the parent element that is drop down. Okay? So if you inspect this element in HTML, you can see that. So the select, this is the element which is representing the entire dropdown, and then okay, and then if you expand the select tag, you can see multiple options. So each and every option is a web element. Okay? Now we'll see how we can handle this type of dropdowns. So let's go to Eclipse, create new package. So I'm creating new class select drop down. Okay? So now we'll see how we can handle the select drop down. So first of all, we need to create a web driver instance, launching application and all those things. So let me do that. Okay? So web driver object created. This is implicit wait, and this is our application launching, and then maximizing the web page. All right? So first we'll see how we can handle the drop down. So whenever you see the drop down, what's the first action we do? We will select the value from the drop down. So we'll select one of the options from this drop down like this, right? So this is a major option, major action we do most of the times. But before that, we have to capture this element. Okay? How to capture this drop down element, and from that how we can select these values. So whenever you see select type of drop down, to handle this we have to use something called select class. There is a predefined class available in Selenium, which is called select. Okay? This is a class. So by using this, we can handle the select type of drop downs. Not every dropdown, only select type of dropdowns we can handle by using select class. So for that, what we need to do is first let us inspect this element. This is a drop down element, and select tag is there, class option, class attribute, ID is there. So if I go back and see the selector hub, and which is given XPath by using ID attribute, it is given XPath for that element. So I'll capture it and try to find that element driver.findElement by XPath. Okay? Now this element we have to store in a variable. I'm taking DRP country some variable, and type of the variable is obviously web element. Okay? Web element. So now import this web element. Yeah. So now we capture the drop down web element, but the next thing is we have to choose one of the options in this dropdown, right? So it is not directly possible. So we can capture this element as a web element drop down, but every option is a web element again. So what we have to do is whatever element we have captured, we have to pass this element in the select class object. So we have to create something called select class. We have to take select. Okay? And this is element we captured, DRP country element, and that we have to pass in a variable select DRP country equal to new select, and whatever element we capture, we have to pass it inside the select object like this. Now we need to import this select from org.openqa.selenium.support. This is a process. So first we have to capture the drop down element, then we have to create a select class object. Inside that object, we have to pass the drop down element. So this is a special class which you have to use if you're working with select type of dropdown, and if you're able to see select tag in HTML, that is called as select drop down. Okay? Now once you create a select class object, by using this object we can perform other types of operations like what are the operations we can do? We can select the value or option from the drop down like this. Or suppose sometimes I want to find how many options are there in the dropdown. I want to count how many are there, or sometimes I want to retrieve each and individual values, right? These are the different operations we can do. So we'll see how we can do those operations. So we captured the drop down as a web element. Now we have passed into the select class object. So now we'll see how we can select the option from the dropdown, select option from the dropdown. So to select the option from the dropdown, we have three methods available in the select class, and we already created an object. So through the object, we can access those three methods. So by using three methods, we can select the value from the drop down. So what are those three methods? Select by visible text, select by value, select by index. So these three methods are available in the select class itself, so we can access them by using an object of the select. So we already created an object called DRP country. So by using this, we can access this method. Only one of the methods is enough. Three options are available, three methods are available. We can use one of the methods: select by visible text, select by value, select by index. Now let me show you how we can select the option from the drop down. So we need to take...











