12. Understanding XPath Locators in Selenium | Types - Absolute & Relative XPath with examples

Опубликовано: 05 Март 2026
на канале: LMTI - Learn More Training Institution
106
5

#lmti #learnmoretrainings #selenium #seleniumjava

Need for XPath in Selenium
XPath (XML Path Language) is a powerful syntax used to navigate through elements and attributes in an XML document. In the context of Selenium, XPath is used to locate web elements on a webpage based on their hierarchy or structure in the HTML DOM (Document Object Model). It is one of the most flexible locators in Selenium, allowing you to find elements when traditional locators (like id, name, class) are not sufficient.

Why Do We Need XPath?
Locating Complex Web Elements: XPath allows you to locate elements based on complex HTML structures, which might be difficult to locate using other locator strategies.

Example: Elements without unique id or name attributes, or elements nested deep within the DOM.

Dynamically Changing Attributes: If the web page uses dynamic attributes (which change frequently), XPath can be used to locate elements more reliably using relative relationships in the DOM.

No Unique Identifier: Sometimes, elements don't have unique id or name attributes, and XPath helps identify them by traversing through the DOM hierarchy or using other attributes.

Locating Elements by Text: XPath can find elements based on their text content, which can be useful when dealing with links or text-based buttons.

Traverse the DOM: XPath allows navigation between elements using parent, child, and sibling relationships, making it very versatile for locating elements that are difficult to access with other locators.

Types of XPath:
XPath can be categorized into two types: Absolute XPath and Relative XPath.

1. Absolute XPath:
Description: It defines the path to an element starting from the root (HTML tag) of the DOM. It provides the complete, direct path to reach the element. If there are changes in the structure of the HTML, this XPath may break easily.

Syntax: Starts with a single forward slash (/), meaning you are starting from the root element.

2. Relative XPath:
Description: It provides a path to the element relative to its position in the DOM. It can start from anywhere in the DOM, and not necessarily from the root element. This makes relative XPath more flexible and robust compared to absolute XPath.

Syntax: Starts with a double forward slash (//), which means that you can search for the element from anywhere in the DOM.

//tagname[@attribute='value'] -- Regular expression of xpath

--------------------------------------------------
"Be a part of LearnMore to learn more and earn more"

Training From the professional
For Admission contact +91 9677569832
mailto:[email protected]

#learnmoretraininginstitution
--------------------------------------------------
#lmti
#seleniumautomationtesting
#javaselenium
#seleniumtutorial
#SeleniumForBeginners
#seleniumjava
#seleniumtesting
#CucumberBDD
#CucumberJava
#BDDTesting
#CucumberTutorial
#bddframework
#BehaviorDrivenDevelopment
#EndToEndTesting
#automationframework
#TestingFramework
#automationtesting
#TestingBestPractices
#learnmoretraininginstitution
#industrystandards
#JavaAutomation
#LearnAutomation
#TestingForBeginners
#AutomationForBeginners
#beginnertutorials
#learnselenium
#codingforbeginners
#softwaretesting
#testautomation
#javaprogramming
#qaengineering

#தமிழில்Selenium
#tamiltutorial
#SeleniumInTamil
#TamilAutomationTutorial
#CucumberBDDTamil
#TestingInTamil
#AutomationTamil
#javaintamil
#தமிழ்Automation
#தமிழில்CucumberBDD
#TamilSoftwareTesting
#AutomationTestingTamil
#TamilOnlineClasses
#TamilSeleniumCourse
#tamilqa #TamilLearningPlatform
#SeleniumWebDriverTamil
#AutomationFrameworkTamil




Disclaimer This channel does not promote or encourage any illegal activities. All contents provided by this channel for GENERAL AND EDUCATIONAL PURPOSE ONLY. Copyright disclaimer under section 107 of the copyright act 1976, allowance is made for "fair use policy" for purposes such as criticism, comment, news reporting, teaching, scholarship and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use. Subscribe, Like , share and comment Thank you for watching

Follow us on

LinkedIn :   / learnmoretraininginstitution  
Instagram :   / learnmoretraininginstitute  
Facebook :   / learnmoretraininginstitute