Syntax of Xpath-
XPath = //tagname[@attribute='value']
// - It means Select the current node
tagname - tagname of the particular node
@ - Select Attribute
attribute - Attribute of the node
value - value of the node
For an Example -
Types of Xpath Locators-
1.Absolute Xpath
2.Relative Xpath
1.Absolute Xpath - IT is the direct way to find out the element .It's start with a single Forward Slash (/) and specific the complete path of an element from the root node .
For Example-
/html/body/div/div[2]/form/input[1]
Real Scenario -
We have taken a ScreenShot above to show the Example of Absolute XPATH (login Page).
/html/body/div[1]/div[1]/div[1]/div[1]/div[1]/form/div[1]/div[1]/div[1]/div/[1]div[1]
2.Relative Xpath - It's Starts from the Middle of HTML DOM structure. It's start with a double Forward Slash (//) and allow the locate element based on their relationship to the other elements on the page.
For Example -
//input[@id='username']
Real Scenario - We have a taken a ScreenShot above to show the example of Relative XPATH(login).
//div[@class='MuiInputAdornment-root MuiInputAdornment-positionStart MuiInputAdornment-outlined MuiInputAdornment-sizeMedium jss8 css-1a6giau']
HTML DOM Structure - The DOM(Document Object Model) is a programming interface that represents the Structure of HTML or XML Document.It's Provide way to access and manipulate the element and content of a web page.
Below Is the example of Absolute Xpath And Reletive Xpath Expression of the same Element Shown in the below.
Xpath Locators-
There are many Xpath Locators , we can find out the Xpath of the Web
Xpath Locators | Find Different Elements on the Web Page |
---|---|
ID | To find the elemnt By ID |
Classname | To find the element By Class Name |
Name | To Find the element By Name |
Link Text | To find the element By the text of the Link |
XPath | IT's Required for finding the dynamic element |
Use - From Above ScreeShot showing below XPATH . By ID, By Class and By Name.
By ID-
//input[@id=":r8:"]
By Class-
//input[@class='MuiOutlinedInput-input MuiInputBase-input MuiInputBase-inputSizeSmall MuiInputBase-inputAdornedStart css-162edyi']
By Name-
//input[@name='hospitalName']
Using Pycharm-