Selenium Locators - Part 2 |XPath Locator | XPath Functions & Operators

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
right so in our previous session we have seen some basic locators from selenium like we have used id and now we have seen like how to use name and then link text partial link text then also we have seen different combinations in css selector and today we are going to see how to use xpath and how we can locate the elements by using xpath okay and this is another very important topic and most of the times while identifying the elements or locating the elements we use x path okay so there are a lot of advantages we have by using x path and we can also locate any kind of element by using x path and sometimes you may not able to look at element by using a normal locator like id name or id name or link text or other locators but by using xpath we can definitely locate an element and wherever it is on the web page and sometimes if you don't find any attributes for the element still you can find the element by using xpath okay so today we are going to discuss uh more about xpath like what is path what are the different types of x path and how can capture the x path or how we can write the x path and also we are going to see what are the different options or functions available in xpath okay so it is little use topic guys so please listen carefully now first of all let us start with what is the next path what is an x path so let me just write some definitions here what exactly x path means xpath is defined as an xml path it is basically shortcut of xml path so we can say xml path is a shortcut we can call as a xpath and it is a syntax or a language for finding any element on the web page using xml path expression so basically xpath is a language which is derived from xml and it is a syntax or a language for finding any element on the web page using xml path so here the xml path is most important so we are going to write a path of the element and simply we can say x path is representing an address of the element so wherever you can see some element on the web page every element is having certain address if you can see some element there should be some address for that element so what is an address means it is a location where exactly the path where exactly it is present on the web page and xpath is representing the address of the element so it is a basically syntax by which we can locate the element by writing xml path and xpath is used to find the location of the element location in the sense again this is the address of the element on the web page using html dom structure so here we need to understand what exactly html dom structure so dom is nothing but document object model so xpath is used to find the location of any element on the web page using html dom structure so what exactly html dom structure means sometimes right so when when you see the when you open any web page let's say i'm opening some web page let's say i have some small web page which open here suppose if you want to inspect any element or if you want to see this let's say right click on inspect and which will give you some kind of html code here right so this is basically called as a dom structure page and uh the all the htm hierarchy all the tags will be aligned in the form of dom structure so let me just show you a small presentation here so if i look at if i look at this small example here this is a html code of the web webpage and internally the browser will create a dom structure like this the same html will be aligned in the form of nodes so for example html and inside the header tag closing tag and again body tag opening tag and closing tag inside the body we have a different elements but on input p and html is closed here the same html structure is representing uh in the different view so this is in this we can see only nodes like html inside this header tag then body tag and inside the body tag there are multiple nodes we have so this is basically called as a document object model and how we can define this dom is an api interface provided by the browser itself and when a web page is loaded the browser automatically creates a dom of the web page and whatever xpath we are going to use that will works on this dom structure and xpath is basically a path path is nothing but a location so wherever the element is present on the web page we can just try to navigate till that element found on the web page or on the dom okay so if that element is not present on the dom then it will give you an error otherwise it can find and when the dom is created as soon as you open the page webpage at the time of loading the page this dom view is automatically created by the browser so dom is basically an api interface provided by the browser itself and every browser is having this api internally and that will generate this dom structure at the time of page loading and xpath exactly works in this location and this is a render view of this particular html view so this is the ui and for this ui this is html code and then this is a dom view structure and xpath is always works in the dom view or dom structure okay remember this so that is all about dom so dom is document object model so which is basically created by the browser itself at the time of page loading and xpath can be used to navigate through elements and attributes in dom so in the dom whatever the elements are available we can just navigate throughout the elements whichever element we have in the dom we can find that element okay so this is the basic information is what is x path and simply say x path is an address of an element x path is an address of element so for example let me just show you something else let's say let me open this page and what is an address what is the next path here so for example let us say i have small logo is here right so when i try to inspect this logo and here uh in dom this is basically dom so here you can see img and this line is representing this particular logo on the web page right so if i just uh locate this element so where exactly this tag is present inside this stack before this tag there are so many tags are there inside html header and body so if i expand this body and again we have a div tag inside the due tag again we have a multiple div tags and inside this div tag and you expand there are so many dim tags are there in the third div tag there is one more due tag and here i can find img so if i write uh something like each and every tag one after another till we reach that element that is a exactly x part of the element okay that's exactly x path of the element so for example select this node and select this line and right click and just copy and you can just see here there are two options available copy xpath copy full xpath so there are two kinds of xpath i will discuss them first let me just say copy full xpath when i copy this full xpath now observe this how it will be and copied here see this this is exactly x path so here we find that element img is a node and where we can find the element so to reach this till this element we have to navigate through each and every node html inside this body node inside this there are multiple due tags are there but we have to go to inside first div tag so one is in representing the index so inside the body if i have a multiple due tag suppose let us say there are two div tags and i want to find element in the first due tag so i need to specify the number then it will navigate to the first div tag and then inside this there is one more div tag inside this there is third view tag inside this there is first div tag and here i can find the element so this is exactly x path of the element and if you just check whether this xpath is locating the element or not what you can do is you can just open the search ctrl f and here you can paste the text path so now we can just locate here when i say enter this is highlighting the logo as well as it is highlighting the line in the html so this is simple example of the x path okay so let me just write it here okay so here this is basically address of the element so to find that element we have to write each and every node we need to navigate through each and every node till we find the element here okay so this is a called as x path and xpath works on the dom so document object model is basically representation of all the nodes from the html okay and now let us see what are the types of expats types of experts so what are the different types of expat so there are two kinds of x paths we have there are two kinds of x paths we have one is absolute x path let me write it over here absolute x path and the second one is relative xpath relative x path so absolute x path is also called as full x path full x path and relative x path is also called as partial x path partial x bar so these are the two kinds of uh x paths we have absolute x path and relative exponent so now let us see what is the difference between absolute x path and relative expert now look at here let me just go to this page and when i'm inspecting this element right so when i inspecting this element this is the html code which is created and when i use this option copy and copy x copy full x path i got this one so this is a full x path absolute x path and now i'll say right click on the element inspect and i'm again right click on the uh text here html and copy and i'm just saying copy xpath only copy x path so now here look at here this is giving a different exponent so here this is x path and this is also an x path and the first one is absolute x path or it is a full x path and the second one is a relative expert or a partial expert so these are the two types of x paths guys so this is an example of absolute x path and uh this is the example of the relative x path i'll tell you what exactly difference means what is the difference and how we can write this x path so in the absolute x path and relative x path so now we need to understand what exactly difference between this absolute x path and relative x path so in the absolute x path we need to navigate through each and every node till that element found in that particular node so to reach image so we have to navigate from the root to tag so if i just look at here html is a starting point right so this is called as a root node and inside this root node there are multiple nodes header node body tubes and there are different node each line in this dom is called as a node and there are different nodes are available so in the relative in the absolute x path we have to navigate each and every node till we find that element and here we exactly find that element but in case of relative x path we don't need to navigate to each and every node like this so relative x path will works based on certain attribute and value and certain property so for example the same logo element there is a id attribute is available so in the relative xpath what happens is star uh slash slash is a starting point so slash slash is representing the entire dom structure and wherever this id find that in the dom it will directly jump to that element and it will find that element so this is a next path and slash img node so here it is exactly finding the element so what is basically difference between absolute and relative x path is in absolute x path we need to navigate each and every node till we find that element whereas in the relative x path based on the attribute it will directly jump to that element it will not navigate throughout the nodes so it will directly jump to that element on the dom structure and it will find the element so that is a one difference between absolute and relatively relative uh relative x path and absolute xpath will start from the root node which is html whereas the relative x path will directly start from the element so here slash slash representing the the whole dom structure inside the dom structure wherever this attribute is find the in dom so from where it will start fetching the element so that is the basic difference so absolute expert will start from the root node whereas relative x path will directly jump to that element and absolute x path will start from single slash whereas relative x path is always start with the double forward slash okay so double forward slash and most of the times observed x path is very lengthy and relative export is little bit shorter than absolute x path okay so these are the main differences between absolute x path and relative x path so the first difference is in absolute x bar we have to navigate each and every node till we find the element whereas in the relative x path it will directly jump to that element and find that element that's the first difference the second difference is absolute x path is start from start with the single slash whereas relative x path is always start with the double slash third difference in absolute x path we don't use any attributes only we use only nodes or tag names in the relative xpath we use some attributes we can use certain attributes and values okay so these are the three differences between absolute x path and a relative expat so difference between absolute and relative x paths okay so the first difference let me write a small note here then you can understand so the first difference absolute x path x absolute x path start from root node whereas relative x path directly jump to element on dom okay and the second difference is absolute x path starts with start with single slash and whereas relative x path relative x bar starts with start with double slash that's the second difference and the third difference is in absolute x path in absolute x path we use only the tags or notes we use only tags or notes okay and then whereas in relative x path in relieve x path we use attributes we use attributes okay so these are the basic differences between absolute x path and relative x path so now we will see a few more examples so how to capture x path so we have seen the differences between absolute x path and relative x path now we will see the syntactical differences so as if you just look at the syntax of object x path and relative x path in observed x path every node we have to specify by separating slash until we reach that element in the relative x path we have to write a simple syntax so even relative x path we can generate or we can automatically write our own expert also so most of the time we can also write our relative x path so if you know the syntax of the relative expert we can easily write our x path but only thing is we need to know the syntax that's it okay so let me just uh show you the syntax of relative expo syntax of relative x bar so the syntax is first we need to start with the double slash and then here we have to specify the tag name and inside the bracket here at the rate attribute equal to the value of the attribute we have to specify in the single quote or double quote so this is a syntax which we have to use to write our relative x path so slash slash here we have to say tag name of the element and some attribute and value of the element and this is the x path and by using syntax we can write any x bar so for example let us say i want to write an x path for the username text box so what i can do is let's inspect this element right so now you can see this is a html line which is highlighted here and this is a just label and this is the actual input tag so this is a html line which is highlighting the username text box now by using this how we can write a next path so directly here itself we can write our own xpath in the search box itself we can directly write our own expert so what is the syntax of xbox relative xpath we need to start with the slash slash and what is the tag name of this element input is my tag name so input in the square bracket we have to specify the attributes of the element so attributes of the element and what are the attributes of the element we have inspect one more time and here so name equal to dx username id equal to text username is a so we can use any of the attributes so here we have to use along with along with at the rate and the name equal to uh either double quotation or single quotation and here you can say the value txt user name so now when i say enter this will able to locate the element so this is exactly syntax which we have to use to write our relative x pathways so if you know the syntax you can easily write our relative expert so this is a very basic relative x path so later i will show you what are the different other options are available in the relative x path so this is a syntax of writing relative x path and this is the example okay so sometimes suppose instead of writing the tag name here you can simply say star so star is representing a regular expression so which will match with all the tag names so then how it is going to work so directly it will jump to all the tags in the dom structure it will find all the dom all the tags and in all the tags wherever this attribute is matching it will go and locate that element directly okay so this is uh we can use either this is also fine so instead of tag name we can also simply say star star representing the regular expression so which is matching with all the tags which are available in the dom structure so this is the syntax which you have to use to write our own relative x path and we are going to see how we can write various ways of writing relative xpath in few minutes so this is a very basic syntax how to write our xpath and suppose there are some plugins are available some extensions are available for the browsers to which will by which we can automatically capture the x path okay so what are the options are available suppose i just want to generate our xpath instead of writing my own xpath i just want to generate x path for the elements and it can be full edge path or it can be relative export whatever so i want to generate automatically xpath of the element so for that we have certain extensions are available for the browser so now let me show you how to capture so if you know the syntax we can directly write our own xpath and if you don't want to write your own xpath you can just capture the xpath by using these extensions so how to capture x path and here there are multiple extensions are available so i'll show you different ways to capture x path it's very easy and most of the time the first approach is this one so if i want to locate this element username i can say right click and inspect and you can find the html line which is highlighted and then right click on the html line copy and you can use these two options copy export copy full expat okay this is a common thing which is available for every browser you can also find this inspect option on the firefox as well as edge browsers okay so you can use these two options to get the x path of the element so when i say copy export this will give you the relative x path and when i say copy full xpath which will give you absolute x path okay this is one option we have so the first option is uh right click element right click on element and then inspect right inspect and after inspecting you can find html write highlight html and then right click and then copy x path okay so this is the one option which is available so first we need to right click on the element inspect that element and on the html we just right click again copy and copy export or copy full xpath so these are the two options which are available so this is the one way we can capture the expert of the element and this option is available on the in every browser so apart from this we also have one more option called pro path extension crow path extension so in the previous days we have some more extensions especially fire firefox like firebug and firepath so nowadays they are not available so they have duplicated from the firefox so now they are not no longer available so the latest extensions are available for the chrome as well as firefox browsers that is called crow path extension so now i will show you how to use this grow path extension which is very very useful extension guys and i will show you how we can work with this crow path extension to capture the x path and uh this extension can be used to write our own x path and you can cross check whether your expert is right or wrong and it will also automatically generate x path so not only expert it will use for css also we can also automatically generate css selector for the elements so now i'll show you how we can use this crow path extension while capturing the x parts so for that what you can do is here and just go to the google and just type crow path extension extension for chrome so which is available for firefox also so you can just cross check so search for pro path extension for chrome and you will see this one crow path google chrome and when you click on this link and which is going to the chrome path web store okay so this is basically called as a crow path okay and by default you will see one option called add to chrome but i already added to my chrome so it is not giving that option for me so in your case you can see here add to chrome button so once you click on add to chrome button which will automatically edit your chrome okay so i already click on this add to chrome and now we can see a small option which is available here so this is basically crow path element and if you don't see this crow path here you can just go extensions list and you can find somewhere in the extensions okay and once you added this then what you can see is when you inspecting this element okay so here along with this dom you can also see the css here in the bottom window right and in this tabs you can find something called crow path tab here okay so once you install crow path extension you will get a new tab here so along with other tabs like computed event listeners dom properties accessibility and then you can see crow path and sometimes you may not see grow path suppose if you under is very smaller then you cannot see like this see this so in that case what you can do is you can just click on this arrow mark and then you can see the crow path okay so this is very very useful plug-in or extension which is available for chrome as well as firefox so now i will show you how we can use this crow path to capture xpath and then so what i can do is just again just drag this window like this and then click on the crow path so once you click on the crow path then it will show you different options here right so here if you just see this drop down you can see relative xpath absolute xpath and css selector so these are the multiple options which are available and along with this by default it will show you all the locators guys that is the main beauty of this grow path and if i just look at here and as soon as you inspect that element like this right as soon as you inspect the element like this let me inspect once again ok so now i am inspecting some element let us say inspecting the username textbox element okay so as soon as i click on the element this will automatically generated a relative x path you can see here so this is a relative x path and sometimes it will also generate absolute x path and here this is the id this is a name and this is a css selector and you can see absolute expert also generated and tag name is also generated so we can use any of these locators in your script to locate this element to identify this element so this is a useful feature of grow path so as soon as you inspect this element it will list out all the locators which are supported by selenium so you can use anything here so relative xpath you can use id you can use name css selector absolute expo tag name so whichever you want you can just use that locator to identify this element okay and apart from this so by default it will show you something called relative absolutely s selector so what you can do is suppose i want to verify i want to write my own x path here or i want to verify my xpath is correctly identifying the element or not so for that what we can do is we can just us specify the next path in this search box and then we can locate the element so for example let me just take the relative x path from the drop down and here i will write my own xpath let's say star star and input is my tag name okay so when i say star star this is invalid pattern right so we have to specify some tag name in the bracket and i'll specify some attribute let's say at the rate so which is given id attribute we can also use name attribute so at the rate name equal to and in that quotation singular double quotations and here i can say value so txt user name and now press enter now it will show you one element is matching so now one element is matching so this x path is exactly identifying the element or it is highlighting the element and here the crow path also we can use to check whether our x path is correctly identifying the element or not and we can also write our own x path here okay and if this x path is matching with one element it will clearly show you one element is matching and sometimes your x path is matching with multiple elements in that case it will show you uh what are the elements it is exactly matching okay so let me just uh show you some other things i'll say i'm opening some different webpage and in this particular page there are so many links are available right so what i'm going to do is here i'm just writing slash a so slash slash a is a representing tag name so when i press enter now we can see this is also x bar so 89 elements are matching so that means there are 89 anchor tags are available 89 anchor tags are available so also you can see here these are the different tags which is listed out here okay so this is how we can use this crow path extension to check all the locators and for example let me just inspect some element ok let me inspect this partners ok now you can see just remove this and put selectors and then it will show you all the locators so this is our relative xpath and class name and css selector and link text then p appealing text and parcel link text peeling test in this is a partial link text absolutely xpath and time so this is very very useful extension guys so we can use it to get all the locators especially for path which is very very useful okay so we are going to use this very frequently to get the x path and to write our own x path and we can check whether x path is correct or not so all these things we can do in this extension okay so this is one way uh we can capture x path by using crow path extension and apart from this we also have one more extension called select task hub okay this is actually enhancement of robot extension and both are designed by one developer he is from india so which is sanjay kumar he's implemented these two extensions so provide and select our hub now let me show you selector hub so selector hub is also one of the extension from chrome so when i say selector hub and there is official website is also available selectorshub.com and if i just look at this webpage you can find which is available for almost every browser so chrome firefox edge and opera so all browsers are supported and he's a guy who is implemented this selector hub okay and as well as crow path so he is a author of copath as well as selector hub now he has made a lot of videos on this and how we can work with the crow path as well as selector hub and all these things now i will also show you how to use the selector hub a few options so let me just go to the web page again let's say so let us open the demo website okay so now let us try to inspect and before that let me show you how we can install selector hub extension so for that what you have to do is so search in the google select us select ours hub for chrome so you can install this for any browsers so if i just look at here select us our chrome so we can just go to uh extensions select task hub extension okay so let's click on this link and it will go to extension web store so group chrome web store and here you can find select us up so you will find add to chrome button here again i have already installed this plugin uh install this extension on my chrome so it is not giving here but in your case you can find uh add to chrome button so once you click on this add to chrome then the selector hub extension will be added to your chrome browser so how we can see that as soon as you open the web page you can find one more icon like this selector hub and if you don't see the icon here you can just go to this and here you can find selector hub and also when i try to inspecting this element and along with the crow path you can also see you can use one extension guys so i already installed both extensions so if you just expand this page little bit you can see select as hub here so once you click on the selector hubs you will see something like this okay and what are all the different options are available okay so basically what is the main intention of using css selector hub so here we can uh use this for writing your own xpath css selectors or everything so the main usage of selector hub is it will give you auto suggestions so it will automatically give you auto suggestions okay so here uh when i just say slash see this it will automatically giving the auto suggestion and i'll say input okay so i'll say input and when i say here see this as soon as i put some bracket it will give you all the auto suggestions and whichever element you want to use you can just select that x path directly you no need to write the complete x path also so it will give you auto suggestions like this and when you select this automatically it is added and one element is matching the html also will be shown here and this will automatically identify the element and similarly when i say slash slash img tag okay say slash and say img so it is not giving any suggestion for us so when i click on enter it is giving lot of img is matching with the five elements and say when is a bracket then it will show you uh again different suggestions like this okay so this is a usage of selector so here we can test all the css selectors and also you can test all the xpath you can write our own xpath and you can test it okay suppose i want to write an x path for this image let's inspect this element and img is a tag name so what i'm going to do is i'll say slash so forward slash we have to use guys so remember here so i'll say img so which is matching with the five elements but we have to specify some attribute for this element and inside this img we can pass some attribute so do we have any attribute we have only src attribute okay so when i say bracket and here it will show you so when i say this it will automatically locate the element so this is how we can just use uh select our hub by passing the x buttons is selectors so which will give you auto suggestions guys it will list out all the expert all the different combinations and whichever is feasible you can just choose the text path and you can use it and also we can test our own x path here okay so this is another extension of the crow path extension so we can use both right so these are the plugins are available or extensions are available for chrome as well as edge and firefox browsers and by using these extensions we can capture x mass so not only xpath we can also capture other locators like css selectors links and tags and everything and we are also going to use this extension very frequently while working with the locators okay so this is how we need to capture the x parts in different ways and after that we have uh discussed about two x paths right so far absolute x path and relative x path so in absentex path we have to write the complete uh all the tags so throughout the navigation it will go through and find the element in the relative expat we have to just specify the attribute and then it will directly jump to that element and it will find the element right so among these two x paths so in interview people will ask you one question so which expert will be preferred okay there are two options are available absolute x path and relative x path but which x path will be preferred to locate element and why so if i say relative x path why we have to prefer relative x bar when i say absolute x path why you have to prefer to absorb x path so this is another important entry equation guys on x path so which x path will be preferred and why so most of the times guys we use relative exponent we use relative x path most of the times we don't use absolute x path so when i say relative x path why we have to use negative x bar this is another important linear equation immediately we will get another question why we need to use relative x path why can't we use absolute expert so there are multiple reasons we have guys but most of the people will say simple answer like absolutely right so now we are discussing about which x path is preferred and why so we have seen relative x path as well as absolute x path and why we have to which x path we have to prefer and why so always we have to prefer relative x pathways okay so why we have to prepare why we have to prefer relative x path so most of the people will say relative x path is very smaller and absolute x path is very lengthy so if i use absolute x path in our script our script will looks ugly and so that's the reason we go for relative x path so that is not exactly right answer guys so there is a technical reason behind that so why we have to use exactly relative xpath why not we go for absolute x path so to understand this let me tell you something so if i just look at here this is my absolute x path right and uh this is my relative x bar let me copy this okay this is my relative x path so when i use this uh absolute x path in our script so the problem with this absolute expert is there are two problems okay there are two problems with the absolute x path or full xpath so the first problem with this is suppose in this absolute x path every node right every tag is representing one node right so for example uh the hierarchy will be like this let me just draw some small picture so this is one node and this is another node and say this is another node so this is a relation guys okay these are the different nodes so this is the root node inside this one more node inside this there are two nodes so let us say i have some element over here so this is my element i want to look at so to locate this element we have to write absolute x path from here so root node then jail node again one more node and here finally we reach it here so how many times you have to specify one two three four so when i write xpath absolute xpath for this particular element right when i use like this suppose tomorrow there are some changes happen so for example so the developer is remove some node here remove the some element from the web page okay then what happens the connection is lost here so as soon as this element is removed this connection is got large so your expert cannot locate this element because there is there are some chances are there because here we have to specify the lengthy node or lengthy tags so somewhere if there is some problem let's say some node is removed from the page then definitely the xpath will broken and then that expert cannot locate the element so this is the one problem you have and other problem is suppose the element is moved to some somewhere else on the web page so previously the element is present here but the same node or same element is present somewhere they have removed from here or place that element in some other place then what happens again the x path is broken so because of these two reasons the absorbed x path will always affect so that's the reason we don't always prefer to use observed x path because somewhere suppose if the element is removed or the element location is out or moved to somewhere else in both the cases there is a problem so in that case our absolute expert will be broken somewhere in the middle then your expert may not be able to locate the element so these changes are commonly happen in the real-time projects because every day you will get the new bills and new elements will be added or existing elements will be removed sometimes the new element will be introduced here sometimes new element will be introduced here then again x path will be broken so if there are any new elements or added on the page or there are existing elements which are removed from the page or the location of the element is got changed so in all the these cases your x path will be broken so in that case your xpath cannot locate your element exactly so that's the reason we don't always prefer to use absolute xpath we always go with relative xpath so when i use relative expert we don't have such problem because we specify certain attribute along with the slasher slash class means it is representing the entire dom structure and wherever this attribute is present that will directly jump to that element and will find that element so even though the new element is introduced or element location is got change no problem at all so this x path will always works so this is a main technical reason why we have to prefer the relative x path instead of observed x path okay so sometimes absolute expert also very smaller than relative expect but still always we prefer to use relative x path because of this reason so in absolute x path when i use these are the problems the element is if new elements are introduced or existing elements or move to some other place or remove the elements then absolute expert will broken and it will it may not work for us so in that case we can just go for relative expand okay so this is the answer for this question guys so what is xpath you will prefer and why always we prefer to use relative x path why because in absolute x path there is a problem when you are moving the element or when introducing new elements on the webpage there is a problem so there may be chances to broke the x path so it may not be able to locate the element always so that is the reason we always prefer to use relative x path it is not related to size of the x path guys it is a technical reason behind that okay and the problem with the absolute xpath is two problems one is while adding a new element on the webpage then what happens the x path will be changed and if you remove the element from the webpage also the xpath will be corrected in both the cases our x path may not able to locate the element okay so that is the reason we always prefer to use relative expat rather than using m0 x path case okay so that is the one thing so this is a very basic understanding uh basic usage of xpath we have discussed so far what is the next path what are the different types of xpath and what is the difference between absolute relative x path and how to write our own x path and then how to capture the x path in the different ways so now i will show you expat different options in xpath and we also i am also trying to show you practically how we can use export options so in xpath this is a very basic x path which you have written guys and apart from this we can also add some more options in the x path okay now i'll show you what are the different options are available and we can use them along with xpath so these are the expert options so we can use the different operators like our end contains start with the text chain xpath so these are the different options we can use along with the x path so now let us see practically how we can use this x path in our script okay so let me just go to eclipse now let me open my eclipse and here is where we have created locators package and inside itself i'm just creating a new class i'll say locators demo file a demo for yesterday we have seen three examples and look at this demo for uh this is rated xbox underscore expats i'm giving and let's take main method and then finish okay so now i'm going to show you different options which are used along with the x path okay so the first thing is let me just show you a small application and then we will try to use a different xpath and before that uh let me just specify something called system.property system dot set property and here we have to pass to arguments i'm using chrome browser i'll say web driver it's a chrome dot driver and the second argument will be the location of your chrome driver so i'm just copying my chrome driver location and then semicolon so this is a setting of the driver and then we have to create a webdriver object press f driver driver equal to new chrome driver and then we have to import the packages related to web driver and chrome driver so import web driver from orgy open qr dot selenium and import chrome driver from org open qr.cnm.chrome okay and then let me launch my browser i will say okay driver dot get is a method by which we can pass the url then it will open the application on the browser so i am opening this application for now automation practice.com slash index.php so this is sample application everybody can access and uh i'm trying to open this application and passing this url as part of the get method so this will launch our application so if you want to maximize the page we have another command called driver dot manage dot window dot maximize so this command will maximize the page all right so now first of all let us see how to use absurd xpath right so absolute expert so on this webpage let me just try to just a second okay so on the web page if i just look at this and here we have a search box and we have a search button okay so i want to pass some value here and then i click on the search button and this time i'm going to use x path and i will show you both absolute xpath as well as relativex path okay so when you're inspecting this element the first element search box and this is a html code which is highlighted right and uh if you just right click directly and if you just go to the crow path it will directly show you so this is a relative x path and if you just come down it will also show you absolute x path okay so we can just use this relative uh absolute x path for now so i am just using this absolute exponent copy this and here i'll say driver.find element by dot and here we have to use x path option so by dot x path in the double quotations we have to pass the x bar so this is absolute x path and once you pass and this will locate the element and once it is located this element dot and direct like a new sending is off and here you can pass the value i'll say t-shirts this is a whole statement and the first element and now the search button i want to locate so inspect this element search element submit search and if we just come down on the crow path you can see at the next path so we can just copy this and here i'll say drive or dot find element by dot xpath so for both relative as well as absolute expert we use same option by dot xpath and this is absolute xpath again and dot say click so click is a method so just one is a search box element another one is a search button element so once you pass the value then i am clicking on the search button so both the places i have used absolute xpath right so let's try to execute this run as java application okay so now it is launched my browser opening my application okay so now we can see here on the search box it is passed some value and then click on the search button so we go to search results here so this is the way we can directly use absurd x path and suppose i want to do the same thing by using relative x path so let me just comment this i'll say relative x path so in case of relative x path we can get it from here itself directly or we can write our own x bar so search button and this is our relative expat and i say driver dot find element by dot x path and here in the double quotations and observe guys so here this is x path which is given in the single quotations so input id equal to and here why we put in the single quotations because so in java in the double quotations inside the double quotations another double quotations are not allowed if you put this double quotations this value like this which will give you an error okay so the problem here is in java the double quotations are not allowed inside another double quotations okay so that is a problem so but still if you want to use a double quotations what you have to do is we have to use some regular expression to avoid this so here we can just put one slash and also here you can put some more slash like this okay and then error is gone so this is a one way to handle this if you still have a double quotations but if you don't have this you can simply say single quotation directly this is a preferable way and you know you don't need to add any regular expression there so by dot xpath so this is my relative x path dot send keys and here i can pass a value i'll say t-shirts this is the first element now after passing this i want to click on the search submit button again i want to use the redirects path and this is a relative expat you can just get it from the crow path and here i will say driver dot find element by dot x path and here you can pass x path dot click so this will also do the same thing so instead of using absolute xpath this time we have used relative xpath so now let us try to execute this run as java application okay so now you can see here it is pass the value click on the submit button then we got the search results so this is a way we can use observed xpath instead of observed expert we can also use relative expand so these are the basic x path very basic just we have a tag name and we have one attribute we specified so we can also use different options along with the x paths so what are those different options we can use different operators like r and contains and start with the text chained expo these are the different methods are available along with the x path and especially when you are treating with the dynamically change element so sometimes the properties of the elements will be dynamically changed so in those cases we need to write a dynamic x paths so in that case we use these particular methods let's continue start with the text so these are very very useful methods which we can use along with the x path and especially the dynamic elements so i will show you how we can use these operators one by one along with the x paths so the first thing we will see r operator how to use r operator let's say x path with x path with or operator so what is an r operator means so sometimes in x path here we specify only one attribute and value we can specify multiple attributes and values also sometimes we can specify multiple attributes or values also okay so for example observe this carefully so i want to inspect this element so a search element okay and uh this is a x path which is given so let me just put the text path here listen carefully guys so this is x path which is by default given by the group and if i just look at this uh html code there are multiple attributes we have so what are the attributes we have so we have id and we also have a name but here by default they have given id only so with this we are able to look at the element okay and apart from this we can also specify some other attribute so for example let us say r so here i can say r are at the rate name so id already used so this time i'm passing name equal to in the single quotations what's the name value here is search underscore query so here i'll say search underscore query so when i press enter this will also be able to locate the element so what extra we have to write in this is let me just clarify this so here this is my first attribute and this is my second attribute and value and in between i'm using r operator so how this r operator works okay so for example when i say r operator either the first attribute should be there or the second attitude should be there if one of them is matching then this will able to locate the element okay so suppose he say id equal to search query top so here id is exactly matching with the same value so you can see id is exactly matching with the search query top and name name is equal to search query so here name is also search query so both are matching so anyway we will locate the element suppose here and say search query 1 i have given some different value so now what happens the first one is matching but the second one is not matching so then what happens still it will go and locate the element because i am saying r arm is either the first attribute or the second attribute one of them should be matched at least one should be matched if both are not available then it cannot locate the element at least a the second attribute or the first attribute one of them should be exist in this particular html either id or name whatever attribute we mentioned here either this one should match or the second one should match even one of them is matching then the whole expert will able to locate the element but when it cannot locate the element if both attributes are not matching then it cannot locate the element okay so for example let us assume this is a and this is b then by using the structure we can understand like this okay so we can say a let us assume this is a and the second part is a b if i use r operator okay and then it will be like this suppose if both are false means this one is not correct and this one is also not correct then there is no element that means this cannot locate the element and the first one is a true second one is false still it return the element and the first one is for second one is true then it still return the element and both are true also it return the element but when it cannot locate the element if both are false and then only it cannot locate the element it will not return the element in all the other cases our operator will return the element so this is our operator so we can use two attributes by separating our operator and if one of them is true then it will match now let us try to test this so here the first case i am passing both are correct so it is locating the element so now what happens is i am changing the second attribute let's say 1 that is not correct but still it is able to locate the element one element is matching so now i am changing the first element and this is not correct let me put single code here ok so now i am changing the first attribute value and this is not correct but still second one is correct it will able to locate the element but when it will not locate the element so first one and second one is both are wrong now when i press enter zero element is matching because the first one first attribute is incorrect and second value is also incorrect so then our operator will never return any value so zero element is matching at least one should be matching either the first one attribute or second attitude then our operator will locate the element okay so this is how we can use r operator and similarly end operator suppose instead of our operator i am using end operator end so what is end means n means the first attribute and second attribute both should be match and then only the element will be written in all other cases element not be written so for example let's say id search query top and the name is search query so both are correct then it will return the element one element is matching one element is matching suppose i will make the first one is false then zero element because among these two attribute one is not matching this is false the second one is true and the first one is true but the second one i say false then still it is not able to locate the element and when i say both are false then it is not able to locate the element so what we have to understand here is when i use end operator both attributes should be matched and then only it will locate the element even one element is now one uh attribute is not matching then it cannot locate the element it cannot written the element so that is all about end operator so r means this one and end means both should be matched okay and means both should be match so if i just look at the table it will be like this so if both are false there is no element and one is to another false still no element okay so you can just do like this and false and true no element both are true then only it will return the element okay so this is like end or operator's case even in the programming also we can say end or operator so similarly here also and in case of r means either one of them should be true then it will return the element at least one should be true if both are false then no element in case of end operator so here it's end operator and operator both should be true so only in this case it will return the element in all other cases there is no element okay so this is all about end r okay now let's see a practical example so x path with r operator so x path with r operator so now i'm going to i'm trying to locate the same elements this time i'm going to use r operator okay so let me just use this x path for the search box how to use this dot find element y dot x path and here in the double quotations i'll put this so this time i'm using r operator guys or r means at least one should be true okay so now both are true so this one as well as this one has to and uh dot send keys so this is a whole x path and dot send keys and here i can pass a value that's it so this will able to locate the element why because we have used our operator either this one or this one should be matched both are matching no problem but at least one should be matched with that attribute then it will go and locate the element okay and similarly we can also write other one so for the text box search button and this is the button search okay so for this also we can write our operator so what are the attributes we have for this we have a name attribute and also we have a something called class is also available right so class is also available we can use the class and a name so by default name is given so here i'll say r or at the right class equal to the single quotation what is the class here btn let's copy the exactly same thing and put it here so press enter this will able to locate one element so because we say r or means either this one or this one should be true so now i'll make the first one is false by adding one still it is able to locate the element and then i'll make the second one is false and then still it is able to locate the element now i'll make both are false and then zero element okay so this is how our operator works so i'll just make the first one is correct or second one is also correct so when i copy this x path you can just try to use like this say driver dot find element by dot x path specify the x path right and dot click so this is a submit button so i can just say click so our operator means either at least one should be matched okay so here both are matching so i'll make the first one is false second one is false still it will locate the element or you can say simply say some x okay and this is invalid but still the first one is correct so it will able to locate the element and in the second one i will make the first one is false but second one is matching so it will able to locate the element in both the cases it will locate the element now when i run this code this will able to do the job okay now it is launched my browser opening the url all right so now we can see here it should enter the value in the search box okay so now we can see it is enter some value and then click on the search button now we got the search results so this is how we can use our operator base okay so either this one or this one one of them should be match then it will go and locate the element so in the first statement i make it seco for second one is false in the second statement i make it first one is false in both the cases it is going to match that element and we also have x path with end operator x bar with end operator okay so let's say xpath with end operator so now we'll see both by using end operator and means both should be match then only it will locate the element or else no ok now again go back to the search button search box and this is x path which is generated let us copy this ok now it is able to locate the element so i am using end operator and at the rate name so name also i'm going to use so what is the name here for that element search underscore query so i'm saying search underscore query so now this will able to locate element even one of them is not matching it will not able to locate the element so now i'll make it the first one is false then you see zero element so i'll make a second one is false then zero element so both should be matched then only it will able to locate the element so now i'm going to use this to locate the search box so here i'll say driver.find element by dot xpath and say xpath and dot send keys and here i can pass the value so here i can say t-shirts okay so this is how we can use end operator either id or name can be used and similarly i'll also try to get the submit button so this is xpath which is given so i'm also adding end operator so this button search will able to match that element if you want to add another attribute you can say and both should be matched so what is another attribute we have for this class is available so at the rate class equal to oh here i'll say class name so this is my class then i can pass it here okay and then this is end operator so both should be matched then it will able to locate the element now copy this and here i'll say driver.find element by dot x path and here you can pass x path dot click so this way we can also use end operator and means both should be matched okay and then only it will return the element or else no so now let us try this run as java application okay now you can see it is enter t-shirts and click on the submit button then we got the search results okay so this is how we can use end our operators along with the x path okay so apart from this we also have few more like contains method and start with method text now we'll see how we can use these functions we can say them as a functions or methods along with expert which is very very useful guys so now i'll show you how to use contains and very very useful and very important function which we have to use along with the expert especially while element attributes are dynamically changes okay so now and one more important thing guys here r and right so these are all case sensitive okay so we have to use exactly in the lower case letters we should not put uppercase characters okay these are case sensitive all right so now let us see how to use contains method xpath with contains method so let me show you the syntax how to use contains along with the x path so the syntax is first of all let's say star slash here i'll say tag name in the bracket here we use contains function inside the contains function here will specify attribute any attribute okay and comma the value of the attribute here this is a syntax which you have to use when i use contains method so slash slash tag name so this is again xpath itself but in along with the xpath we also use contains method so slash slash tag name contains and this is a whole function it is taking two arguments the first argument is attribute and the second attribute value so what exactly contains method will do is suppose if this attribute is having some value okay so every attribute is having some value okay so for example let us say i have something called id okay so id is a first name so id is my first name so if i want to locate this element by using id normally how we will write an x path we will write x path like this if it is a normal basic x path i can say tag name is say input is my tag name in the bracket i will say at the rate id equal to in the single quotation directly i can specify the first name so this is a normal exponent which we can write to locate this element so here we directly specifying the attribute and value so the attribute value should be the same then only this x path will work right so for example let us say i don't want to pass a complete value like this i just want to specify some value right and then what i can do is we can use contains method i'll say the same thing like this input in the bracket it's a contains contains at the red id comma and here you don't need to pass the complete value you can just pass some portion of the value and then what happens is in this example so what contains method will do is contains method will check the id contains this one or not id contains a first or not if the id contains the first then it will go and match that element and we can also use something called name also so i say first or else's name so it should be part of the actual value okay so in that case we use this contains method guys so contains is a method which will verify the attribute value is a part of the actual value then it will go and locate the element so that is all about contains method okay which will be very very useful when you having dynamic element guys so let me just give you a small scenario where exactly which will be very useful for us so this is a basic extract so this is a basic x path and this is using contains okay now i'll show you where exactly uh we use this particular x path okay so for example let us say i have a small button let me just give you a simple example like this so i have a small button let's say it is a stopwatch and my button uh the text is it says start okay and when i click on this button it will give some numbers increment some numbers and this button same button is turn into stop so i have only single button and the id of the button is start here okay the id of the button is start and as soon as i click on the button it will turn into stop again if i click on the stop again it will turn into stop so like the same button it is interchanging like this and when the button is on start stage the id is a start the button is starting to stop the id is a stop okay so but there is a single button which is available and the id of the button will be changing dynamically depends upon the state so initially id is a start then it is again becoming stop again it is becoming start so the same button is interchanging while pressing the button so i want to write a locator x path which will able to match this element in both the cases okay so now observe this carefully so when i write a locator like this this is normal locator okay so slash slash let us uh assume tag name is input and here at the red id equal to at the right id equal to when i say start so when i write x path like this which will able to match only the first case if the button id is start then only it will match but this will fail in case of second case if the button status is turned into stop then this will fail and suppose if i write like this and here if i just say instead of start when i say stop like this now what happens this will work only if the state is stopped and once it is turning to start this will also will fail so instead of writing these two x paths i can just write one x bar which will able to locate the element in both the states okay so then how we can write an expat so in that case i can write an x path like this slash slash input right here i can use contains method contains and here we have to find something common which is there in both the properties so id so what is a common in both so here it is a start here it is a stop so first two characters are common right and that i can specify here i'll say st so now what happens this x path will able to match in both the cases even if it is a start button this will able to match even it is turning to stop then still it is able to match so this is called as a dynamic expertise so this is a dynamic x path so at the runtime the properties of the attributes will be dynamically changing and runtime in those cases if you still want to locate the elements we should able to write the dynamic x path and especially while writing the dynamic x path we use contains method so there is one more method start with so you can also use that particular method because in both the ways both are starting with the same so instead of using contents you can also use start with method start with us also method because id is always starting with st so here it is starting with st here also it is starting with sd okay so you can also use start with method but what is the difference between contains and start with contains method will check this one is pa this one is present in the whole value so st will be there in the beginning or in the middle or the end wherever it is doesn't matter but in case of start with the value should exactly start with st okay it should not be there in other places so that is the basic difference between contains and start with so you can use these two functions very frequently to handle the dynamic elements so those properties are dynamically changing so contains method and also we have a start with and very very useful methods which we are going to use along with the x pathways okay so now we will see practical examples how we can use this functions along with the example so this is exact scenario where we can understand we can use where we can exactly use contents and start with all right so now let me just try to use them practically let's go to eclipse and now this time we are going to use contains and start with functions so x path with contains okay so xpath with the contains so we already seen the syntax how to use contains so this is syntax input is my tag name of the element contains so attribute and the value so the value when you need to pass a complete value we can just pass some portion of the value this will able to locate the element okay so now let's see how to use contains method along with the x path okay and for that again i'm just taking the same example so let's take a search button and submit button let us inspect the search button and this is x part which is given so we let us try to write our own expert now with contest method okay so i'll say slash slash input is my tag name and here i'll use a content so audios contains i'll say contains in the bracket and what is attribute you want to use here you can use any attribute you can use id or you can use name whatever so here i am saying observe this carefully contains at the rate i am using id right so id comma the second argument will be the value so actually the id is search underscore query underscore talk search underscore query underscore tom but here i'm just saying only search underscore query search underscore query that's it so this will able to locate one element or you can also specify query underscore top so instead of search underscore query you can just specify a query underscore top so this will also able to locate the element so one element is matching okay so this is how we can use contains method let me just use this driver dot find element just a moment say driver dot find element by dot x path specify the text path dot send keys and here i can pass a value like this okay so here contains id by actual what is the id value here search underscore query underscore top so actual value is this one search underscore query underscore top this is actual id value right but what we have used here just we have used query top or you can use search underscore whatever you want you can use it so now the second one let's go to the second one submit button so for this we have a name is available class is also available so now what i'm doing is slash slash input in the bracket at the rate and this time i'm just taking a name attribute i'll say name comma in the single quotations actually what is the value of the name submit underscore search but i'll say only submit only submit so we have to we have to say contains right contains so condition name and then bracket so now press enter so it is saying zero element guys so why it is saying zero element input contains uh at the rate name input is my sorry the tag name is not input guys so tag name is button here okay so the button is a tag name i'll say button now press enter now you can see this will able to locate two element guys because somewhere some element is also having the name at give it which is having submit so that's the reason it is saying two elements are matching other than this there is one more element somewhere it is going to match so what i can do is instead of submit i can simply say search then it is able to match a single element okay actual value submit underscore search but i am just using search here and now we can use this value to locate the element i'll say driver.find element by dot xpath specify that xpath dot this is a button so i'll say click method dot sorry so two brackets and dot click so this will actual values actual value is this one so actual name is this one submit underscore search is actual value submit underscore search is actual value but what we have given so search we have given in this contains so which will able to match the element so this is how we can use contains method mean so in the contents we no need to pass a complete value of the attribute we can just pass some portion of the value okay so it is just uh similar to link text and partial link text so similarly here also we can choose just pass the partial value so when i run this as java then it will do the same thing now it is launching my browser passing the url okay so now it is enter the value click on the search button now we got the search results all right so this is how we can use contains method guys so along with this we also have one more method called start with method now we'll see start with method x path with start with but there is a small difference between contains and start with as i discuss here so when i say contains method right so this value so this is a complete value we can just pass some portion of the value or we can say search or query or tab whatever you can pass you can specify inside the contains but when you start with method whatever value you are passing here that should be the first value in the attribute value so for example here it is a search i have used and it should be starting with the search actual but here when you start with instead of constrain it will not work why because it is not starting with the search the starting point is submit okay now let us try to use the same examples here instead contains i am using starts with okay and also here i am using start with okay now observe so will it work or not so let's see the first example in the first example when i say start with so what is the exact value of id search query top and it is starting with the search but what i have mentioned here query underscore top i mentioned so this will not able to locate the element so what you have to do is we have to specify the first one search underscore query then it will able to match that element so because id is starting with search underscore query so we have to specify search underscoring then only it will match the element now see the second element so here actual value of the name is submit underscore search but here i mentioned the search that is the next element so it is not starting with the search so this will also will not work it will not able to locate the element so what we have to do is we have to use submit or submit underscore anything is fine so in case of start with we have to specify the submit now let us test this x path whether it is working or not so we can just paste over here plus enter so now it is able to see this it is matching with the two element case again so start with name equal to submit when i say name equal to submit it is matching with the two element because some other element is hiding name starting with the submit so there is a reason to matching elements so then what you have to do is there is underscore is also available so after assignment you can just specify underscore also then one element is matching right so you can use this expert now so here you can use that x path so then it will able to so again exactly this name is starting with submit underscore so segment underscore we specify so this time start with function will work so when you start with the value of the property or attribute should be the starting point of the exact value or the original value and then only start with function works okay so now let me execute this okay now it is launching my page okay now it is enter the value and press the submit the search results so this is our search results all right so this is how we can use start with functions so contains and start with functions then we also have one more function called text function [Applause] x path with text function so now i'll show you how we can we work with the text function and this is also very important one so suppose we can use the text function to locate any kind of element which is having text equal to something so let me just show you simple example here and suppose here i have something called some links are available women dresses and t-shirts right so when inspecting this element let's say inspecting this element movement and what is it is showing so this is anchor tag which contains some href and title and class so if you just look at here you don't see any id or any class or any name attributes right so what exactly which is having it is it is having some link text woman is a link text so you can locate this element directly by using link text you can use uh driver.find element of buy dot link text you can use or partial link is also fine but you can also locate this element by using text methods okay so let me show you how we can use a text method so to locate this element we can use a text method let me just go to the crow path again and take the relative x path so text method along with the x path okay so now in a say slash slash a so there are 153 elements are there so exactly this element is tag is a right so when it says last slash a which is matching 153 elements now here so now here so i don't have any name attribute or i don't have any idea about nothing here so what i can do is i can get this element directly by using a text method okay so how we can do this so here i'll say text method and which is equal to and what is the text you are expecting women so i can just specify that w-o-m-e-n okay then enter zero element it is giving zero element so why it is zero element a text so a is of text is a method and equal to i think here something is so in the lowercase letter is there so you can see in the html we can find lowercase letter so that we have to specify that's the reason i said this is the case sensitive so when i enter then it is exactly matching with one element so now you can see woman is located similarly you can highlight other elements okay so text method which we can use to uh check the equality like whichever element we have in the webpage we can locate any other elements by using the text method so we can use this one to locate this element i'll say driver dot find element driver dot find element by dot x path and here we can use text equal to women and dot you can say click so because that is a link so i'm just clicking on the link so this is remain tab so this will be able to locate the element by using text and click on the press the click perform the click action on this element okay now let us try this run as java application okay so now it is launched my browser okay now it should click on the women tab so now it is clicked so it is navigating to some other page okay so this is how we can just locate the elements by using text method also so these are very frequently used methods along with the x path guys okay so so far what are the methods we discussed we have discussed r and contains start with and text and we have something called chain index pathways so change x path means we can write multiple x path one after another sometimes even one x path may not able to locate element then we can chain another x bar so i'll tell you what is exactly chained x path means let me show you the one more example of chained xpath so what is chained x path how it will be how it look like so here let me just go to the page so what is a chained x pathways suppose let me just inspect this element search button okay search text box so this is actual element and let's look at this dom so input is my this is exact element this is html which is representing the search box and this is the input app right so above this there is one more input tag is this is another element this is another element this is another element so all these elements are present in one single element which is called form okay form so form is a parent element inside the form there are multiple elements are present if i just look at this html you can clearly understand this so form is a parent element in this we have a sub element so these are all inputs elements like text box like search button logos everything is present inside the form so instead of directly searching this element okay what i will do is first i will directly go to the form and from there i will search this element so first i will write an x path to locate this particular form parent okay so for that what i'm going to do is slash slash the tag name is a form and here and what are the attributes are available for form id is available so here i'm just saying at the rate id head rate id okay equal to so what is the id value search underscore search box so this is my id of the form so i'll say search box so this is my form when i enter this see this which will be able to locate one element so that is your form so this x path is reached till this particular form so once it is located this form inside this form our search element search box is present here input tag so then we can write followed by another x path i can write slash and here i can write input tag and then which element you want to find out here the fourth element so you can just find input of 4 then which will able to match the element so because in the fourth input type you have an element so this is the x path you can write like this so this is called as a chained x bar you can write many ways i will show you chained x path so in this what i have done first i have located the parent element from that there are multiple child elements are there so one two three four inputs are there fourth input tag is representing my search box so there's a reason as f input okay this is one x path which is representing the search box or instead of specifying index you can also specify the attribute and value so instead of four i'll say at the rate at the rate id at the rate id equal to so what is the idea of this tag input act search underscore query tab so i'll say search underscore query underscore top you can also specify this so this will also able to locate the element so you can pass the index here because there's a fourth element or you can directly specify the attribute and value here so this is also called as a chained expat x path followed by another expat so first we reached here from there we reached here and this one and this one both are correct to locate the search box right so similarly suppose i want to locate the button so even the button is also part of the form i guess yeah so button is also part of the form is a channel element of the form so in the same xpath what i can do is i can simply say so instead of input i can say button is my tag say enter this will match up one element because there is only one button tag here under form so i no need to pass the index here if i have a multiple button tags then you can specify the number so when i say one still it is matching with one element because there is only one button so here one index is optional so if i don't say one by default it will take one so this is chain index path to locate the button or suppose if we want to specify the attribute of the button you can still specify so in the bracket i can specify let's say name equal to submit search so i can use that attribute at the rate name equal to submit underscore search enter so this will able to locate the element so first we have reached the form inside this a button attribute is there so button is a channel element of the form and then we can specify the attribute value so this is also right for locating the button so these are called as a chained x path so x path followed by another x path x path is followed by another x path ok now let us try to use it so here driver dot find element by dot x path and here i am taking this one to search box to locate the search box and dot send keys and here i can pass the value so t-shirts and similarly second element i am using this chain index path and here i can say driver dot find element by dot x path and let's say x path chain index path dot click so here i can on the click action okay so this is how we can also write our chained x path now let us try to execute as a java application so now it is launching my browser launching my application and then yes now it is enter the value in the box and click on the search button so now we go to the search results okay so this is how we can use uh chained x path guys so these are all the different options are available in the xpath so there are so many functions are there like this guys okay so these are the very commonly used functions along with the x path and very very useful and especially while working with the elements those properties are dynamically changing so we use all these options okay so this is all about xpath options okay so in the next session i will discuss about xpath access there are few more options available along with xpath which are called as expert access so we will discuss them in the next session okay so that's all for today's session i'm stopping here
Info
Channel: SDET- QA Automation Techie
Views: 37,935
Rating: undefined out of 5
Keywords: Python, Selenium with Python, Selenium webdriver, Automation, Testing tools, Selenium tutorials, Python tutorials, Manual testing, SDET, Java, selenium with java, web services, postman, soapui, rest assured, SQL, Programming, Software Testing material, selenium videos, python videos, automation vidios, jira, jmeter, performance testing, functional testing, QA, QC, Agile testing, SDLC, Automation Step by Step, restapi, Locators, xpath, dynamic xpaths
Id: jD37dxX3ZNo
Channel Id: undefined
Length: 101min 41sec (6101 seconds)
Published: Wed Sep 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.