Hi friends so we are going to see XPath today in this session.
We had discussed about 8 types of Locators in our earlier session of Selenium, and XPath is one of those Locators. So, XPath is a Locator, which helps in locating Elements.
XPath is called as xml path and it can be called as the path of the element from it’s root node or the immediate node.
There are 8 types of locators in Selenium, but we are discussing about XPath seperately, So there will be something speacial about XPath or you can say that XPath is an important type of locator.
Now, As we know that locators are used to locate element, and We can use some other locators like id, name or anything else to locate the Element, then why should we use XPath, what is so special about xpath.
So, the answer is that other locators like id, name or className are the attributes of an element, but what if an element doesn’t have these attributes, then what should we do, How should we locate that element, So XPath solves that problem for us.
XPath can locate any element for us.
There are 2 types of XPath
if suppose we want to find out the XPath for any element then what do we need to do, we need to inspect that element and how do we inspect an element. We need to right click on the element and click on inspect and then we can see the html dom of the element is higlighted in console and then we need to press ctrl f and here we need to write xpath of element.
We can write Absolute Xpath or Relative Xpath in this.
Now, Let’s go to our Dummy eCommere Website and inspect any element and we see that the html dom of the element is highlighted in console.
So, Now, If we follow the xml path for this element upwards to the root node, then we can get the Absolute Xpath of this element.
If we follow the xml path for this element upwards to it’s immidiate node, then we can get the Relative Xpath of this element.
So, Now let’s find out the Absolute Xpath and Relative Xpath of an element.
There is nothing much to understand in the Syntax of Absolute Xpath,
But if we talk about syntax of Relative XPath, then we need to consider below things in mind.
Note – We never ever use an Absolute Xpath because of all the above disadvantages.
We have covered below topics in this session.
Objects, Classes and Constructor in Javascript Classes and Objects A class in any programming language…
We will start from object oriented programming basics like What are different concepts in Object…
Why we can not over ride a Constructor This is a very important question, that,…
What is Arrow Function In the last session, We had discussed about Anonymous Function. Anonymous…
What is Anonymous Function Anonymous Function is a type of function which has no name…
What is Map, Reduce and Filter Map Filter and Reduce are higher order methods for…