Hello everyone, in this video session, I am going to explain Part Seven of selenium four that is using get rect method for retrieving the height with x&y coordinates of the given UI element okay. So, in Selenium three there used to be two methods days that is get size and another one is get location whereas get size method used to give you the get you the height and width of the given URL with whatever the URL meant you pass to this method it will give you the height and width of that element. Whereas, forgetting the x&y coordinates of the given new element you have to use date location So, get location method used to give will give x and y coordinates of the given UI element to this method. So, this is a story of selenium three guys And there came something known as Selenium four, okay.
So, in Selenium four currently we have the alpha version of selenium four okay. And in Selenium for the introduced a new method that is nothing but get rekt method okay. So, using the single method, we can get the height weight x and y coordinates of the given element. Here you have to use two UI elements, sorry two methods. Here you have to use two methods for getting the height weight x&y coordinates of the given a new element, but here using this single method that is get rekt we can Get the H with x and y coordinates of the given UI element. So that is the difference this Get rekt is new method in Selenium four guys.
So in this video I am going to practically demonstrate how to use this get rect method for retrieving the side with x&y coordinates of the given element just before that before that I will explain you the older Selenium three methods that is good size and good location methods which were used for getting the height weight and x&y coordinates okay. We have to use two methods for getting here guys, but here only one method. So what is height? What is good? What is excellent what is like? Okay, let me explain that first.
Let's say this is a web page. And let's say there is a button here on this web page. Now this is the height of this button this okay this portion is the height of this button. So this is the height of this button okay? And this is the width of the button okay whatever the line I'm drawing just by seeing the image and seeing the button okay this is the width of the button from here to here, it is here to here. Now what is excellent what is like from here to here is x Ray Rice Okay, from left side of the page to the position of the button is x, this is x and from the top of the page to the position of the button, okay, this is why so nice.
Using this get size method in Selenium three we can get this height of the button and using this, get size we can get from here to here that is without the button and using the gate location we can get the x coordinate of the button that is this length of this thing again x coordinate is nothing but the length okay whatever the length is here x will be zero here starting here zero it will increase and whatever the position here x will be that position okay and y will be my coordinate is like from top zero is here and then the number will increase of the y coordinate until a button is reached and some number will be there for this y coordinate like the case so we can get the height with the x&y coordinate of this x&y coordinates are just to represent the position of the button on the webpage is nothing more than that okay.
Whereas height is height of the button which is width of the water simple terms. Now, that we practically demonstrate this get size and get location in Selenium three first followed by Get rekt in Selenium four, okay, open this eclipse ID and here is a map this is Selenium project. This is a Maven project guys okay this is a Maven project and in Palm dot XML file of the Maven project we need to provide the dependency test for this Selenium three. So if you go to this young vn repository.com to search for Selenium three here, okay. We have we are getting something like selenium, Java. And you see this is the last version of the Selenium they just click on this and this is a dependency tags for this Selenium three okay.
And just paste it here. The dependency test for Selenium grid and save it. Now this project has a Selenium three configured with right this project is configured with Selenium three. So now create a new class here. Say demo seven. Select this public static void Main.
And inside this main method, right few samples steps like driver manager dot driver dot setup. Okay and WebDriver driver is equal to new chrome driver then maximize the browser window window dot maximize then basically which you some time I'm unit dot seconds sorry not seconds fight. Okay, now open the application URL what application you are on this is application URL I want to open. So for that I will be using driver dot get as usual. And import this chrome driver from Selenium three. This WebDriver also got imported from Selenium three because this project is now configured with us Linear three dependence right 3.14 1.5 Now guys, as I explained as I explained in Selenium three we have this gate size and gate location methods.
I'm going to first practically demonstrate these two methods for giving you the height and width and for giving the x&y coordinates using this get location method. Okay, so let me choose an element. So let's say I want to take the height I want to gather the height and width of this button, okay on this webpage, so for that I need to create a web element for this button. So I will start with driver dot find element. Okay how to get the locator for this button inspect this button guys. It will give you the sum.
It will give you the HTML of this button. As you can see it is called view to do is that I will use ID locator so I'll say by.id the value is beauty to locating the button. Then put a semicolon here It will return you the web element okay this is like a button element button element is equal to for the most and say create local variable you see web element for this button got created and now we are going to get the height and width of this button in Selenium three this is Selenium three guys okay whatever I'm going to share is nothing but alien three in Selenium three to get the height and width of this button we have to use a method known as get size okay with this web element got we have to say get size it will get you the height and width of the button.
So it will return you the dimensions. So I will say D is equal to and for the most obvious answer create local variable dimensions D is equal to button element dot get size. Now let's fill the height and width of this button. So d dot get height okay d dot get height. Now you can get the height race okay. This gets size has given as Gordon like dimensions of this button which has a height and width also.
So now using these dimensions we are getting height now System dot out dot print lm d dot get weight so this is how guys by using the gate size we can get the height and width of the button now how to get the x&y coordinates have this button so for that can I use get sighs no guys, okay, if you try just write the dot get x, x is not there. It's not available in that method. Okay, so for retrieving the location of this button that X and Y positions of this bar have a required element you have to use date location. So let's use this locate location. With this net this a web element, button element.it location this will return point okay, this will return point I'll say p is equal to Okay, p is equal to something and hold the mouse on P and say create local variable y and p is equal to will come.
Now let's print the x&y coordinates of this button further do the same System dot out dot print ln P dot get x and again, System dot out dot print ln P dot get y okay? x coordinate and y coordinate. Now once you've got all these things in place a driver closes it will close the browser window. Okay, so let's run this and see whether we are able to retrieve the whole With x and y coordinates of the given button using the dead size and get location methods so this is Selenium three guys okay. You see the height of the button the width of the button, the x coordinate of the button and y coordinate of the button got retrieved from the but from the UI and from the UI page and then printed here. So, this is in cillian, three guys, this is Selenium three.
So what about Selenium four? So what about Selenium four in Selenium for a new method about introduced that is get direct method okay. Using this single method we can retrieve the height weight assigned by here two methods are required here only one method is required. Okay. Let me practically demonstrate that. So before that, let me get the dependencies for What a Ambien Repossi and selenium, Java and so forth what is the latest version of selenium for this alpha three Okay.
I will take the latest version of selenium alpha version for alpha version copy this and they will this three point something and then put the four point something okay alpha version of alpha three version of selenium four and sage okay Selenium four is getting downloaded and configured in this project. Now the Selenium four is configured in this project. So we can use the methods of the Selenium for now. So, what is the method I was saying get right method of selenium for okay. So, we have to use it with the same get element button element dot get right okay. So it will return rectangle okay it will return rectangle so say R is equal to or the mosaic say create local variable now using the same get right guys you can actually get all these four values hit hide gateway to create extend gateway you can see that now System dot out dot print ln r dot get height okay first one, then System dot out dot print ln are with no System dot out dot print ln r dot get x then System dot out dot print ln r dot get y like this we got height with x&y, okay.
All right we assigned y of the required UI element, right like so here in Selenium three how to use get height, this get size and get location but in Selenium for only one method is an upgrade that is get right for retrieve the height width. X and Y okay? Find this methods are also there in Selenium for guys, they are like carry forward okay. Anyhow this newly introduced method that is get like method can be used for retrieving the hydrated sex and one Okay, so let's see, let's run this code and see so I will use a System dot out dot print ln nine then put this here so that you can see the difference okay I'll somehow somewhere say Selenium four here and then the more all this extra stuff that is coming okay. So then you can see this is why Selenium three and this is why Selenium four okay this methods are from Selenium three These are old methods guys.
Okay, these are the these are they're from the circuit hydrate with the get excited get this is a good size and get location methods are there in Selenium three onwards, okay, but you Selenium for this Get rekt got introduced. Let's see how this method From the Selenium three and methods from the Selenium four are working okay methods introduced in Selenium three methods from Selenium four are working let's run this we will get the same results we will get the same result so here you can see right get tracked can give you height weight x&y coordinates in a single row, instead of using two methods, you can simply use get rect method to solve your problems right. So you see, that is the same thing as height height with weight. This is like x coordinate this x coordinate a y y, okay, so it's giving you the same result so we can use get right instead of these two methods.
So this will simplify things. So that's it guys. This is how we have to use get rect method for retrieving the height with x&y coordinates of a UI element in Selenium for so in the next video session, I will explain how to open a new blank window Okay, how to open in new blank window or a new blank tab in Selenium for using new window okay using new window command in Selenium four, we can open a new blank window or a new blank tab. That's fine. This This was not there in Selenium three. Okay, this was introduced in Selenium four.
This is one of the new features of selenium four, where you can open a new blank window or new blank tab. I will explain in detail about opening of a new blank window or new blank tab using new window command of selenium four in the next video session. So that's it, guys. See you in the next video session. Thank you. Bye