Course Content
Selenium Python First Script
Selenium Python First Script
0/2
HTML Form elements
HTML Form elements
0/1
Handle HTML Frames
Handle HTML Frames
0/2
Handling Dropdown Lists
Handling Dropdown Lists
0/2
Selenium Action class
Selenium Action class
0/1
Selenium Python for Beginners [ 2024 ]
About Lesson

XPath Location Strategy

XPath stands for XML Path. It is a method of locating nodes in an XML document. Another alternative is to locate an element on the web page by its XPath. This method is used for every XML and HTML document.

An XPath expression can be either relative or absolute. The two types of XPath are as follows:

  • Absolute XPath
  • Relative XPath

Absolute XPath

Absolute XPath starts from the root node. It holds the location of all elements from its root. The absolute path starts with a single slash /

Absolute paths are not recommended. The drawback is that they will most likely fail with the slightest changes to the element’s path, and web application changes can invalidate them.

Relative XPath

A relative XPath is based on the relationship it holds with its parent element or, any strong element close to the target element that has an ID or NAME attribute associated with it. The relative XPath starts with double slashes //

The general syntax to create relative XPath is as follows:

//tag_name[@attribute=’val’]

Example : //input[@name=”username”]

 

Join the conversation