Using getRect() for retrieving height, width, x and y co-ordinates of an element

Selenium 4: New Features Selenium 4 - New Featues
16 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€47.98
List Price:  €67.18
You save:  €19.19
£39.89
List Price:  £55.85
You save:  £15.96
CA$70.14
List Price:  CA$98.21
You save:  CA$28.06
A$76.87
List Price:  A$107.62
You save:  A$30.75
S$67.31
List Price:  S$94.24
You save:  S$26.93
HK$389.14
List Price:  HK$544.83
You save:  HK$155.68
CHF 44.67
List Price:  CHF 62.54
You save:  CHF 17.87
NOK kr553.51
List Price:  NOK kr774.97
You save:  NOK kr221.45
DKK kr357.84
List Price:  DKK kr501
You save:  DKK kr143.16
NZ$85.68
List Price:  NZ$119.95
You save:  NZ$34.27
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.46
৳5,972.22
List Price:  ৳8,361.58
You save:  ৳2,389.36
₹4,221.07
List Price:  ₹5,909.84
You save:  ₹1,688.76
RM223.35
List Price:  RM312.71
You save:  RM89.36
₦84,627.22
List Price:  ₦118,484.88
You save:  ₦33,857.66
₨13,887.22
List Price:  ₨19,443.22
You save:  ₨5,556
฿1,722.96
List Price:  ฿2,412.28
You save:  ฿689.32
₺1,727.27
List Price:  ₺2,418.32
You save:  ₺691.05
B$289.99
List Price:  B$406.01
You save:  B$116.02
R907.60
List Price:  R1,270.71
You save:  R363.11
Лв93.82
List Price:  Лв131.35
You save:  Лв37.53
₩70,211.45
List Price:  ₩98,301.65
You save:  ₩28,090.20
₪185.71
List Price:  ₪260.01
You save:  ₪74.30
₱2,946.36
List Price:  ₱4,125.14
You save:  ₱1,178.78
¥7,736.95
List Price:  ¥10,832.35
You save:  ¥3,095.40
MX$1,021.22
List Price:  MX$1,429.79
You save:  MX$408.57
QR182.26
List Price:  QR255.18
You save:  QR72.92
P683.46
List Price:  P956.90
You save:  P273.44
KSh6,472.14
List Price:  KSh9,061.51
You save:  KSh2,589.37
E£2,482.01
List Price:  E£3,475.01
You save:  E£993
ብር6,118.22
List Price:  ብር8,566
You save:  ብር2,447.77
Kz45,640.87
List Price:  Kz63,900.87
You save:  Kz18,260
CLP$48,886.48
List Price:  CLP$68,444.99
You save:  CLP$19,558.50
CN¥362.07
List Price:  CN¥506.93
You save:  CN¥144.86
RD$3,012.01
List Price:  RD$4,217.06
You save:  RD$1,205.04
DA6,712.40
List Price:  DA9,397.90
You save:  DA2,685.50
FJ$113.77
List Price:  FJ$159.29
You save:  FJ$45.51
Q385.78
List Price:  Q540.13
You save:  Q154.34
GY$10,455.70
List Price:  GY$14,638.82
You save:  GY$4,183.11
ISK kr6,980.70
List Price:  ISK kr9,773.54
You save:  ISK kr2,792.83
DH502.76
List Price:  DH703.91
You save:  DH201.14
L910.90
List Price:  L1,275.33
You save:  L364.43
ден2,951.80
List Price:  ден4,132.76
You save:  ден1,180.95
MOP$400.70
List Price:  MOP$561.01
You save:  MOP$160.31
N$906.31
List Price:  N$1,268.91
You save:  N$362.60
C$1,838.97
List Price:  C$2,574.70
You save:  C$735.73
रु6,749.45
List Price:  रु9,449.77
You save:  रु2,700.32
S/189.51
List Price:  S/265.32
You save:  S/75.81
K201.21
List Price:  K281.71
You save:  K80.50
SAR187.68
List Price:  SAR262.77
You save:  SAR75.08
ZK1,382
List Price:  ZK1,934.92
You save:  ZK552.91
L238.86
List Price:  L334.42
You save:  L95.56
Kč1,216.06
List Price:  Kč1,702.59
You save:  Kč486.52
Ft19,746.05
List Price:  Ft27,646.05
You save:  Ft7,900
SEK kr551.69
List Price:  SEK kr772.42
You save:  SEK kr220.72
ARS$50,176.71
List Price:  ARS$70,251.41
You save:  ARS$20,074.70
Bs345.34
List Price:  Bs483.50
You save:  Bs138.16
COP$219,443.60
List Price:  COP$307,238.59
You save:  COP$87,794.99
₡25,456.77
List Price:  ₡35,641.51
You save:  ₡10,184.74
L1,262.95
List Price:  L1,768.23
You save:  L505.28
₲390,155.46
List Price:  ₲546,248.87
You save:  ₲156,093.40
$U2,130.69
List Price:  $U2,983.14
You save:  $U852.45
zł208.13
List Price:  zł291.40
You save:  zł83.27
Already have an account? Log In

Transcript

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

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.