Relative Locators

Selenium 4: New Features Selenium 4 - New Featues
32 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
€46.61
List Price:  €65.26
You save:  €18.64
£39.96
List Price:  £55.95
You save:  £15.99
CA$68.39
List Price:  CA$95.75
You save:  CA$27.36
A$76.59
List Price:  A$107.23
You save:  A$30.64
S$67.96
List Price:  S$95.15
You save:  S$27.19
HK$391.36
List Price:  HK$547.94
You save:  HK$156.57
CHF 45.64
List Price:  CHF 63.91
You save:  CHF 18.26
NOK kr547.39
List Price:  NOK kr766.40
You save:  NOK kr219
DKK kr347.66
List Price:  DKK kr486.75
You save:  DKK kr139.09
NZ$83.90
List Price:  NZ$117.46
You save:  NZ$33.56
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,478.47
List Price:  ৳7,670.29
You save:  ৳2,191.82
₹4,165.48
List Price:  ₹5,832.01
You save:  ₹1,666.52
RM238.82
List Price:  RM334.37
You save:  RM95.55
₦63,338.32
List Price:  ₦88,678.72
You save:  ₦25,340.40
₨13,897.67
List Price:  ₨19,457.85
You save:  ₨5,560.18
฿1,850.91
List Price:  ฿2,591.43
You save:  ฿740.51
₺1,624.82
List Price:  ₺2,274.88
You save:  ₺650.06
B$257.30
List Price:  B$360.25
You save:  B$102.94
R950.48
List Price:  R1,330.75
You save:  R380.27
Лв91.20
List Price:  Лв127.68
You save:  Лв36.48
₩68,703.94
List Price:  ₩96,191.02
You save:  ₩27,487.07
₪189.75
List Price:  ₪265.67
You save:  ₪75.91
₱2,888.99
List Price:  ₱4,044.82
You save:  ₱1,155.83
¥7,775.71
List Price:  ¥10,886.62
You save:  ¥3,110.91
MX$852.59
List Price:  MX$1,193.70
You save:  MX$341.10
QR182.06
List Price:  QR254.90
You save:  QR72.84
P692.34
List Price:  P969.33
You save:  P276.99
KSh6,723.65
List Price:  KSh9,413.65
You save:  KSh2,690
E£2,394.34
List Price:  E£3,352.26
You save:  E£957.92
ብር2,838.38
List Price:  ብር3,973.96
You save:  ብር1,135.57
Kz41,866.62
List Price:  Kz58,616.62
You save:  Kz16,750
CLP$47,624.47
List Price:  CLP$66,678.07
You save:  CLP$19,053.60
CN¥362.22
List Price:  CN¥507.14
You save:  CN¥144.92
RD$2,935.86
List Price:  RD$4,110.44
You save:  RD$1,174.58
DA6,715.26
List Price:  DA9,401.90
You save:  DA2,686.64
FJ$114.57
List Price:  FJ$160.42
You save:  FJ$45.84
Q388.02
List Price:  Q543.26
You save:  Q155.24
GY$10,449.73
List Price:  GY$14,630.45
You save:  GY$4,180.72
ISK kr6,996.60
List Price:  ISK kr9,795.80
You save:  ISK kr2,799.20
DH506.56
List Price:  DH709.23
You save:  DH202.66
L890.37
List Price:  L1,246.59
You save:  L356.22
ден2,871.51
List Price:  ден4,020.35
You save:  ден1,148.83
MOP$402.79
List Price:  MOP$563.94
You save:  MOP$161.15
N$957.24
List Price:  N$1,340.22
You save:  N$382.97
C$1,837.34
List Price:  C$2,572.43
You save:  C$735.08
रु6,654.43
List Price:  रु9,316.74
You save:  रु2,662.30
S/185.19
List Price:  S/259.29
You save:  S/74.09
K189.75
List Price:  K265.67
You save:  K75.91
SAR187.49
List Price:  SAR262.50
You save:  SAR75.01
ZK1,304.12
List Price:  ZK1,825.88
You save:  ZK521.75
L231.95
List Price:  L324.76
You save:  L92.80
Kč1,174.43
List Price:  Kč1,644.30
You save:  Kč469.86
Ft18,295.47
List Price:  Ft25,615.12
You save:  Ft7,319.65
SEK kr543.08
List Price:  SEK kr760.35
You save:  SEK kr217.27
ARS$43,653.36
List Price:  ARS$61,118.20
You save:  ARS$17,464.83
Bs344.96
List Price:  Bs482.97
You save:  Bs138.01
COP$194,549.13
List Price:  COP$272,384.35
You save:  COP$77,835.21
₡25,038.42
List Price:  ₡35,055.79
You save:  ₡10,017.37
L1,232.29
List Price:  L1,725.31
You save:  L493.01
₲370,833.91
List Price:  ₲519,197.15
You save:  ₲148,363.23
$U1,917.12
List Price:  $U2,684.12
You save:  $U767
zł201.11
List Price:  zł281.58
You save:  zł80.46
Already have an account? Log In

Transcript

Hello everyone, in this video session, I am going to explain part nine of selenium four. That is let you locators in Selenium four. They have introduced a new concept known as layer two locators. So what is the purpose of this array to locators? Instead of name? Let's say there is a web page.

And there are few UI elements like this. And there are some other UI elements surrounding this UI element. Okay. Let's say you want to look at this UI element. Okay, let's say you want to look at this UI element. But unfortunately, due to some XYZ reasons, you are not able to look at this UI element directly.

Okay, the UI element which is in the center, directly, in the case, guys, we can look at this, we can, since we are not able to look at this directly, we can look at this UI element with the help of the other ones. Other UI elements surrounding it. So you can look at this required UI element with the help of a UI element, which is on the left side of this UI element or you can look at this UI element using the UI element which is on the right side of the required UI element or you can locate this required UI element using the UI element which is which is below this UI element or which is above this UI element. So using any of these UI elements, which are nearby this required UI element, we can look at this UI element with the help of with the help of this array do locators concept okay.

With the help of this later locators concept, we can look at the required UI element, which is not able to be located directly with the help of the nearby UI elements like the UI element which is on the top bottom left and right. So, for these guys in Selenium four, they are this related look at this concept is providing two things like one is class that is related locators plus other one is Another one is with tagname method. Okay. And along with that there are other things like.below.table.to write off, okay and there are different methods like left off. Okay to be used as part of this relative locate a sponsor that I will be practically demonstrating it to you right now. So let's switch to the practical board now.

Okay, let's switch to the practical mode, where I will radically demonstrate how to use this relay to look at a concept for the for locating the required UI elements using the nearby UI elements. So let's open Eclipse ID. So we have to create a Maven project and configure that navigate project with the Selenium for so right now when I'm explaining this video session, we have the Selenium for alpha version, the steps for creating an Mavin project and configuring that with the Selenium four and other stuff already explained as part of the first video of this Selenium four video series. Okay, you can go through that first video and come back here hoping that you have created this Maven project and configure that with this Selenium four. Okay, it's available in the repository guys, you can go to me and repost it and get this dependency fine and hoping that you're you did all these things.

Then let's create a new class here. And name these classes they were nine and select this public static Weidman and say finish. Now inside this main method, inside this main method, write some basic stuff like WebDriver manager dot chrome driver dot setup, and then WebDriver driver is equal to new chrome driver We'll open up Chrome browser. So I have to demonstrate driver Okay, for the most important driver interface and chrome driver class, then maximize a browser window using this command driver dot manage dot window dot maximize. Then implicitly wait for some time do some seconds, like time unit, or seconds after this basic steps have been written. Let's open the sample application here.

Let's see what my first example I would explain this. So I will take this sample application tutorial stranger.com slash demo. Okay, and I will go to this login page directly copy this URL The login page of this website, tutorials ninja.com slash demo and log in page and then provide that into the driver dot get URL. This will place the driver URL provided. Now, after opening this application after opening this application, what I'm going to do here is I am going to enter the email address here and password here. And let's say I want to click on the login button.

But assume that you are not able to click on locate this login button directly. So what I will do here is after entering the username password, then I will with the help of this related locators concept, I will click on this login button. Okay, let's say you're not able to look at this login button. But with the help of the surrounding us. Let's say this password you element. I'll click on this login button.

Okay, so let me practically demonstrate that for you so far now after going to this login page what to do how to enter the email address inspect this email address field so that it has some ID guys input email is ID copy this ID. And here say driver dot, find element by.id and provide the ID value. And say dot click the dot send keys and you have to give the email address here to enter the email address into this text field. So I will enter this email address that is Ravi dot Kiran one at the rate gmail.com. After that, I have to enter the password. Okay, after that I have to enter this password.

Inspect this password field and as you can see, it also has some ID copy this and say driver dot find element by.id or the password ID then sendkeys how to enter the password here. So let's say I have given the password here. Then guys, let's say After this entering this username and password here I have to click on this login button. Assume that you are not able to look at this login button directly with almost any type of locators. So I want to take a different approach here where Okay, I will say you see I will be using relay to locate us now, in this statement I'm going to use a relay to locate this concept for locating that button button. Okay, find element.

Here instead of saying buy or something I will say relay to locators. dot this is a locator it's okay not locator locator later locator dot. The method name is with the tag name inside the tag name. So, let's identify the tag name of this login button. It has a document diet name as input. So let's give the tag name as input here.

Okay input time they have to look at this button with the help of the nearby You element let's say I want to locate this login with the help of this password text field. Okay, this login button is below this login button that we have to click is below this password text field. So what I will do here is the tag name of this button I have given first Okay the first thing that what is the tag name of this login button it's input when I inspect this and use it the tag name is input I have given that already now say a lot which is below this UI element having the tag name as input is below by locator. Okay, here I'll give this locator of this login that is Password field, okay. So by that Id input password is nothing but the locator for locating this password field right?

And this and here saying that and here saying that this login button is below this password failed. So now we have what this driver dot find elements are later located with tagname of this login button which is below the which is veloza password field we are given so far right what we have to do on this what we have to do on this thing we have to perform click operation right click that's it. Now, now see guys it will enter the username and it will enter the password and it using this related locator it will locate the login button and click OK to see we have said that the login button has the target tag name as input and and it is below this particular UI element that is below this text field. Okay having the input field input tag. So now when you run this this will work guys.

Okay. This will work November application Then it will enter the username password and click on the login button. You see it has clicked on the login button and we got logged in. We got logged in. Okay, you can see the logout. So let me click on logout again.

Fine. So So this is how guys, we can use the related locators for locating the rig, look required UI elements with the help of the other UI elements which are surrounding it's like this is this UI element is there a bow this required UI element right? So or this UI element that we want to click is below this UI elements like that. So I have few more examples guys. So after I explained all these examples, one after the other one, your confidence will increase and we will be understanding this later. Look at this concept.

More. Okay. So the second one is how we're using to write off I will take a different application here. Let's say this one where.blogspot.com I'll copy this application URL and paste it into this driver dot get here. And then what I'm going to do here is I'll explain. So let's say I, let's say I will enter some text like this into the stock screen, and I want to click on the search button.

Okay, but I let's let's assume that you are not able to click on this search, you are not able to locate the search button directly. So you're going to take the help of this text field to locate this search button using the relay to locate us with the help of how to use this to write office, okay, because why because this search button is on the right side of this text field. So we will be using this to write off the previous example where I demonstrated relate to locator using dot below. Why because this login button was there below this text field, but now in this application in this app Application the search button is on the right side so we have to use a different thing like to write off Okay, let me practically demonstrate anyhow I will clear out all this stuff. We'll go to this will open this omega.blogspot.com now after going there okay after going there I will enter some text into this text field inspect this so it has some name is equal to Q.

Okay I'll copy this value of this name locator driver dot find element by dot name and a dislike q dot sendkeys I will enter some text into the text field first Foxtrot comm let's say after entering the text into this text field. Now I want to click on this search button. Okay I want to search this text on this website. So in order to click on this search button, I will look at the search button but let's say Given that you're not able to locate, so in that case, I'll use this text field, they'll pop this text field, I look at this as button with the help of the relay to locate us. So let's do that driver dot find element. Since I'm not able to locate this search button directly, what I'm going to do is I'm going to use layer two locator dot with the tag name.

So what is the tag name of the search button? We have to find it out first. So it has a tag name as input as okay this attribute and has a tag name as input this input so I'll use this input here the double quotes I'll just provide and say dot i am this is to the This button is on the right side of this text field right. So I will say to the right of and I will give the same locator here by now name you okay then dot Arctic if you're not able to look at this The Search button directly. So using the related locators concept with the with the by locating this text field, which is on the, okay, which is here, and this is what is on the right side offset field, we can locate the required search button and perform click coverage.

So let's run this and see whether this is working or not. So it will open the application it will enter text into this text field and click on the search button. You see the search button got clicked there. That's the reason you got the search result here. Okay, so guys, using the related locators, we can look at the UI element which is on the right side of the one, which is on the right side, okay, of the other UI element. Using this to right off now let's go with another example, where I'll be using the combination of two things like I'll be using both below and to left off Okay, I'll be using the combination of two things.

So let's say this is an example guys that I'm going to demonstrate now, let's say to left off, right. So let's say this text, I want to click on I want to, let's say get the text of the submit button. Okay, I want to retrieve the text between the HTML tags of this Submit button. So, for that, I have to look at the submit button and assume that you are not able to locate this Submit button. So what you will do is, you will locate this Submit button with the help of this one and this one, okay, just for the demonstration purpose, I am taking these two things, guys, okay, you can do the combination, this, this Submit button that you want to look at is below this text. And to the left side of this login button, right.

The submit button that you want to look at is below this text and to the left side of this login button. So I'll use the same thing, same concept. So you already seen I'll clear out this stuff. Now without waiting any way what I will do here is I will inspect this text okay the submit button is then below this text let's say inspect this and let me create a expert or something for this say, I will copy this text double slash to text is equal to view this Okay, this will look at this text and the submit button is below this text. So let me start writing driver dot find element. So what led you locator dot with the tag name?

The tag name for this button is this button guys. Okay, this is a submit button right button. Okay, so I'll give the tag name s. button which is which is below this petition. texts. Okay, this is a sea expat expression for locating the sticks. So I will use this copied I copied that expat expression dot which is below by dot expert.

I will paste that expat expression that I created just now. Fine. I and I will say enter and say dot Okay, and to list off to the left side of the left side of this login button the submit button is on the left side of this login button so let me inspect this login button and let's create it has no it doesn't have anything button with the text login. So I'll create another XPath expression here that is double slash button text is equal to login and okay this locating this login button copy and paste The left side of bi dot export is the locator for locating the login button, then semicolon and this will return you the web element as a web element. What is the development about Submit button element right. So, this so what we have done is the UI element that you want to look at has the tag name s button.

This is a button tag name, and it is below this below this text align to the left side of the login button. I have given all these things and this will result this will return a web element of Submit button. Okay, since you're not able to look at the submit button directly, we have user locators off the avoid UI element or to the right side UI element here to look at this web element of Submit button. Now, let's retrieve the text of the submit button. So System dot out dot print ln Submit button dot get text. Okay, this will retrieve the text so that when it prints you can see that this web element is nothing but we'll get another this web element is nothing but a submit button from the output.

So let's see whether the real Submit button has been located using this lady locators or not. If it retrieves the submit button text, then submits then it will it has located the required Submit button. Okay, if it comes on, let's run this code. Open application URL and that thing has been already done. As you can see the submit button text has been printed here okay. The text between the types of the submit button has been printed in the output.

That means that this UI element is nothing but Submit button. Right, we are able to locate the submit button with the help of the other UI elements which are there on the right side and on the label. Okay, we have used both combination this.below.to list two things we have used here. Similarly, I'm going to explain another example. That is to write off and do less stuff. Okay, I'm going to demonstrate to write off and do less stuff.

Let me take this example guys, where I want to look at this login button. Okay, but unfortunately, due to some XYZ reasons, assume that you are not able to look at this login button directly. Now I want to look at this login button with the help of Submit button and register button using this relay to look at this concept. Okay, this login button is to the right side of this Submit button to the left side of this register button. I'll be using this two UI elements health and with help of relative limits. I'll be locating this login button.

Okay. So for that, let's clear out that stuff and then say start with driver dot find Element Relative locator dot with the tag name. What is the tag name of the login button we have to find out first Okay. That you want to look at the button you want to look at what it has a tag name as button, pop it is and paste here. I now said dot the button is on the right side of the button is on the right side of the submit button. So inspect this create some locators for this button.

That is a double slash expat expression I am creating text is equal to MIT and Santa is locating the Submit so I am taking the explicit expression of the submit button and then say here by dot expert and then we will export expression of this Submit button. Then after that got to the off the left off to the left side of this register okay register. So inspect this register button and create sorry, this one okay. They start here and this will look at the Register button. So copy this export expression of for locating this register button and then by dot export paste it here okay to right side of the submit button and to the left side of register button locate the new element having the tag name s button. So that's the whole concept provide a semicolon here and then it will return a web element which is nothing but a login button login button element is equal to okay to find out whether the login habit has been really located or not.

What I'm going to do is I'm going to retrieve the space between the tacks of this located button. If log in is printed in the console, that means login button has been located with the help of the submitted waster buttons which are there on the left side and right side of these buttons. Okay? So, System dot out dot print ln login button element, dot get text. Okay, save it and run it. So the application is opening now.

So let's see whether the text of the login button got printed here or not. You see the texture between the dance of the login button got printed that means this is nothing but the login button. The UI element that got located is nothing but the login button with the help of the buttons which are there on the right side and left So here we have used to write off and do less stuff. Okay? things in relative look at concept. A few more examples guys to make you clear off this relatable Okay, this concept I'm going to use more examples here so that you can understand other stuff on how to use a relay to locate us.

Fine. So let's say I want to look at Okay, I want to look at all the hyperlinks which comes under this Compendium them. Okay, there are different number of hyperlinks here I want to look at all the hyperlinks under this Compendium they will link so let's use that. So, after going to the application after going through that application, what you have to do you have to say driver dot find element. Relate you locator dot with the tag name. So I want to look at all the anchor texts which come under this compendium of links Okay, all the hyperlinks which come after this companion do link I want to look at so here all the all the things that I want to look at should have the anchor tag, the hyperlinks I want to look at which comes under this Compendium new so that's the reason I have given anchor text because all the hyperlinks generally have the anchor text right will have the tag name as a so I have given a okay I want to look at all the texts which all the hyperlinks which have the which come after this will come below this companion.

So to state that, I have to say dot below okay dot below. And this hyperlink I want to provide that is anchor text having this text Compendium div. So I will copy this text and say by dot link text into the text between the tax so this is the tag name, amen. Every hyperlink will have the tag name I only write every hyperlink you see either this hyperlink or this hyperlink which is coming below this convenient new link all all these hyperlinks have the anchor text. So, here all the anchor text will be located hyperlinks will be located which come below this company name The only okay provide a semicolon here as you already know that there are multiple hyperlinks that are going to be located okay which are below this Compendium they will link it should not be saying find element you should be saying find element space okay.

So, this will look at multiple UI elements. So we have to say find elements and this will return a list of web elements list off that element. So I will say simply say list is equal Okay. Now, I will print out so import this from Java dot util. Now after that, what I will do is I will retrieve all this hyper In text text between the anchor texts for example, this hyperlink has some text like only testing block right? I would like to print all this stuff for that I will say for int i is equal to zero.

I want to print all the hyperlinks text of all the hyperlinks that got located with the help of this find elements i.is then listed dot size I will say okay since there are multiple hyperlinks located I will say I equals zero i less than this dot size i plus plus. Then inside that I will say System dot out dot print ln listed dot get off. I this will return the hyperlink one after the another one as part of the loop and I will retrieve the text of each and every hyperlink. Okay text between the tags of the hyperlink cells radio text points. So let's run this code to see whether all the hyperlinks are This Compendium deal got printed or not okay, run this has opened application and you have already done that. You see a lot of things have come here guys okay, so open a pop up new tools so here what are there let's find it out under Compendium we have new tools that new tools is there here only testing blood tests wisely jQuery automation desktop.

Okay. YouTube's only testing blood tests wisely jQuery automation test everything is there apart from these two things guys, you already got something like open a pop up window and blogger why we got these things. Because here you see this hyperlink is also below this companion. They only as part of this page under this Compendium do not only these hyperlinks, guys But also this hyperlink is also under this companion view. And if you can see there is another thing like blogger, this blogger link is there at the bottom of the page. Okay, this blogger link is also under the Compendium dealings, that's why it was printed.

Okay. So if you don't want all the hyperlinks are linked if you don't want this open a pop up window and a blogger and you want to only print these hyperlinks only okay which are there between the Compendium deal and automation desktop, you can filter that okay, how to do that simple guys. So here you said dot below and to this say dot table. Okay, below below Compendium deal but Abel table by dot link text table automation tester, okay, so I'll give this link next but locating that hyperlinked so all the hyperlinks which are below the Compendium do and about automation tester should be printed no okay that is the last example is below enable and giving. So here save it and run it this time it will not print all the hyperlinks which are there below the Compendium new hyperlink instead it will print only the hyperlinks which are there between the companion deal and automation tester hyperlinks Okay, so go to the Eclipse and see that new tools only testing blog despises jQuery okay only for this for hyperlinks, which are there between the Compendium deal and automation tester, but in today's, so, this is how guys we have to use a layer two locators for locating the UI elements which are not which are not able to look at directly with the help of the nearby UI elements.

Okay. In Selenium for fine. And as you can see here, after this radio locators, if you say dot i will after a year Sorry here not here after this week tagname if you say dot here you will get a lot of override and overloaded methods here. So Abel Abel below below like that are there we can we can experiment them yes okay a lot of methods are there Yeah, newer methods also, okay near the kind of default near near method is also built into the relay to look at a concept okay. So you can try everything guys a bow below near and do left off to write off all this methods of relay to look at the concept of selenium for for locating the UI element, which are not able to look at it directly. But that's it guys.

In the next video session, I am going to explain how to print the Chrome Dev Tools console locks. Okay, in Selenium four, they have given some options were using which you can print the Chrome Chrome browsers go to dev tools, console locks. So this thing I am going to explain in detail in the next video, guys So that's it guys see 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.