Selenium xpath examples.


Selenium xpath examples A. When it comes to XPath in Selenium, there are numerous ways to write using XPath, but choosing the right method will depend on your unique test cases as well as your Mar 5, 2025 · XPath axes help to find elements based on the element’s relationship with another element in a document. What is XPath? XPath stands for XML Path Language. Oct 1, 2021 · XPath Example: Usage of XPath functions and Axes in Selenium What are XPath Functions in Selenium? Sometimes while working in a dynamic web environment, it becomes challenging to locate a particular web element by using general attributes such as name, class, etc. Below are several Selenium code examples for web automation testing in Java which cover various common actions such as navigating to a website, locating web elements, handling alerts and frames, etc. It is often Types of XPath in Selenium. d) Tag, Class and Attribute Jul 8, 2024 · XPath Functions in Selenium. There are two types of HTML tables published on the web-Static tables: Data is static i. Relative XPath in Selenium refers to locating elements on a webpage based on their relationships with other elements, starting from a specific context node. findElements( By. How to write an xpath based on element's text with that piece of html: PDF - Download selenium-webdriver for free Previous Next This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3. Example- //input[@name=‘fname’]. Now let’s try automating this using Selenium. Most of what you’ll do with Selenium is a combination of these basic commands. 2 days ago · Relative XPath. XPATH as the strategy (parameter), and required string value (that locates the input text field) for the locator parameter. XPath is a component of XSLT standard provided by W3C. Recommended Paid Courses to Lean Selenium and Locators: Selenium WebDriver with Java -Basics to Advanced+Frameworks; Selenium WebDriver With Java – Novice To Ninja + Interview Dec 14, 2023 · Writing XPath Commands in Selenium. It consists of a path expression along with some conditions. <anyTag> Make Selenium Easy </anyTag> (Inner text has spaces in beginning and end. Or the xpath could be relative. For example, below Amazon's website: Unable to select an element via XPath in Apr 12, 2025 · Following Sibling in XPath. Types of XPath in Selenium . XPath for all the following sibling elements when element's id is given. The XPath node, which can either be the starting point of the path to the node where the element is situated or a point relative to some other point There are primarily two types of XPath used in Selenium: Absolute XPath. Read more Aug 2, 2023 · There are primarily two types of XPath used in Selenium: Absolute XPath. This is because the selenium IDE is basically used to record and replay tests where the path of elements already mentioned by its ID or name attribute value. It allows for both simple and complex queries to find elements by their attributes, text content, or hierarchical position. It is a general format used to find out element through a relative XPath in Selenium. It's a direct path from the root element to the desired element. Example: How to apply XPath as a Script Oct 27, 2023 · In Selenium it is commonly used to find the web elements. At my job, I built a tool-independent test framework that builds locators for multiple tools, including Selenium, using our own simple syntax. evaluate( xpathExpression, contextNode, namespaceResolver, resultType, result ); Apr 23, 2024 · Selenium 4 Relative Locators Demo. Single Slash is used to create XPath with absolute XPath i. XPath, which stands for XML Path Language, is a query language used to navigate through XML and HTML documents. 0 in tandem with Selenium may achieve the desired result. Mar 27, 2025 · XPath Locators help locate HTML elements for Browser Automation using Selenium. There are two types of XPath in Selenium. Aug 27, 2024 · Java and C# WebDriver, WebElement and ShadowRoot classes all implement a SearchContext interface, which is considered a role-based interface. It is used to traverse the elements and attributes of an XML document. Use relative XPath expressions whenever possible to make your tests more robust. A Sibling in Selenium Webdriver is a function used to fetch a web element which is a sibling to the parent element. Read our exhaustive cheat sheet on XPath Locators with examples. Using XPath with Selenium lets you locate web elements on a web page. We use it to traverse among elements and attributes in an XML document. linkText() Accessing links using their exact link text is done through the By. By understanding XPath functions and best practices, you can write effective, maintainable, and powerful test scripts. . 0/3. The examples above provide a starting point for using XPath in Selenium with Python. <br>Following topics are covered in this tutorial: <br><br>Introduction to Xpath <br>XML DocumentX <br>Xpath Syntax <br>Types of Xpath <br>Xpath Functions <br><br><br>Selenium playlist: https://goo. There are many other ways to construct XPath expressions to find specific elements on a web page. Example 1: Locating an Element by ID Jan 3, 2024 · Selenium Commands with Examples - SELENIUM; Selenium WebDriver Commands List ; Synchronisation commands - SELENIUM; What Is Selenium RC : A Step-by-Step Guide for 2024; XPATH Usage in Selenium; Skills That Will Make You a Champ Software Tester with Latest Trends; Tricentis Tosca Automation Tool (2024) Tosca Interview Questions for 2024 Selenium - XPath for input text field. xpath (“XPATH”)) method is used. To find an input text field using XPath in Selenium, you can call the find_element() method on the driver object, with By. However, it's brittle and can break with small changes in the web page's structure. The World Wide Web Consortium (W3C) defined XPath in 1999. Absolute XPath ; 2. Find out the difference between absolute and relative XPath, how to use contains, starts-with, chained, and or statements, and more. Let’s go through them step by step to learn how to build XPath with examples. 7, Maven, Intellij, Selenium 2, ChromeDriver, Chrome XPath Helper plugin. ) Feb 21, 2019 · It also gives a brief idea on types of Xpath, Xpath Functions along with an example. Locating Strategies- (By XPath- Using Multiple Attribute) In this section, you will learn how to locate a particular web element by XPath- Using Multiple Attribute. I don't have write too many xpath locators, though. Table Of Contents Sep 26, 2024 · XPath extends beyond (as well as supporting) the simple methods of locating by id or name attributes, and opens up all sorts of new possibilities such as locating the third checkbox on the page. It is the backbone of many automation and web scraping tools like Selenium, Puppeteer, and BeautifulSoup. Note: This solution requires additional setup and is not out-of-the-box with Selenium. Mar 6, 2015 · We will start with the introduction of Selenium and XPath – what it is and how to use it, then we will see the working model of how to use XPath in Selenium tests. findElement(By. //*[@id = ‘username’] 1. xpath() is commonly used to access elements of WebTable in Selenium. XPath is a versatile tool that helps you locate elements on a webpage based on various criteria, such as attributes, text, and relationships with other elements. In this example, we’ll automate booking a flight on a fictional travel website using some of these relative locators in Selenium 4: Scenario: Search for a round-trip flight from San Francisco (SFO) to New York (JFK) departing on March 20th, 2024, and returning on March 25th, 2024. ∙ Relative XPath will directly identify the element in DOM through the element’s attribute and value specified in it or text associated with it. However, if there are two links that have the very same link text, this method will only access the first one. Feb 12, 2024 · Also Read: Selenium PHP Tutorial: A Comprehensive Guide, with Examples & Best Practices. All the candidate elements can be assigned to a List when webdriver. Sibling in XPath Example: Mar 3, 2025 · Learn how to automate Selenium datepicker selection using JUnit, WebDriver, and sendKeys for efficient form testing on DemoQA. The add-on can be downloaded and installed like any other plug-in. For example, we will show you how to manually and easily find web elements in Selenium using XPath. To grab a single first element, checkout – find_element_by_xpath() driver method – Selenium Python Mar 28, 2025 · Learning Selenium Tool commands is easy. Relative XPath We can write by using the following ways, Attribute Based XPath; Text() Based XPath; Contains() Based XPath; Collection Based XPath; 1. Each type has its own use case, advantages, and limitations. W3Schools offers free online tutorials, references and exercises in all the major languages of the web. What follows is a guide to using XPath in Selenium, from basics to real-world examples. Relative XPath: It starts from the current element or node and is much more flexible. Jun 9, 2010 · In my opinion the best answer was provided by the person who posed the question. Dec 31, 2024 · Relative XPath in Selenium. In the above example, we saw that the xpath used yielded two matching elements with xpath values, input#c_bs_1, and input#c_bs_2. We already aware of the Functions like text(),contains(),starts-with(),last() and position() in Xpath. Setting up your Selenium environment Feb 15, 2019 · Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selenium Training | Edureka - Download as a PDF or view online for free XPath is a robust tool within Selenium for locating and interacting with web elements. Here are few basic XPath examples in Selenium: Xpath=//input [@name=’password’] Dec 28, 2024 · The XPath could be absolute xpath, which is created from the root of the document. XPath Syntax Cheat Sheet XPath Syntax Overview. Understand how to find elements by Text using Xpath Selenium for accurate test automation. Use the // shortcut sparingly, as it can lead to slow XPath queries. Mar 4, 2025 · Why XPath is important in Selenium. Role-based interfaces allow you to determine whether a particular driver implementation supports a given feature. Let us consider an example in which we will try to locate the Google Search Engine Text box by XPath- Using Or. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more. For the best possible experience, you should also open up the website in the browser (on desktop), and view the HTML source code side-by-side. Consider a small Donation and support this page. Absolute XPath. Aug 12, 2024 · Relative XPath: Starts from a specific element and navigates through the DOM hierarchy to locate the desired element. Follow the steps 1 min read . This will return the male radio button. If you are using Selenium IDE, then it has inbuilt support for absolute XPath only. It provides a way to traverse the structure of an XML or HTML document and select specific elements based on their attributes, text content, or position in the document hierarchy. XPath in Selenium includes several methods such as Contains, AND, Absolute XPath, and Relative XPath to identify and locate dynamic Apr 16, 2023 · Types of XPath in Selenium . Our XPath tutorial is designed for beginners and professionals. gl/NmuzXE Jan 30, 2021 · XPath, or XML Path Language, is a query language that allows you to navigate through elements and attributes in an XML or HTML document. Here's a Selenium XPath example for Jun 20, 2024 · How to find elements by XPath in Selenium: Example. There are also functions available which help to frame relative xpath expressions like contains(). Jan 17, 2022 · XPath types in Selenium. (dot) – Dot at starting represents the current node. These are just a few examples of how to use XPath in Selenium. By using the existing attributes and functions, if we cannot locate any element in the DOM at that time, we try to use multiple Xpaths in a chained form [ using more than one XPath]. It starts from the root node and ends with the desired node, providing a complete path. May 30, 2022 · 💡 The developer tools also provide a convenient way to get the XPath expression for any DOM element. linkText() method. 5) XPath Node Jan 29, 2013 · It shows that xpath for Google Search Button is correctly written. Cross-browser fit: XPath locator works across various browsers without any exception in finding elements. Here's a Selenium XPath example for Jul 15, 2013 · Using that xpath-checker add-on is a great idea! I never thought to look for one. Oct 22, 2024 · Use the Following XPath Syntax: There are two main types of XPath in Selenium: Absolute XPath: It starts from the root node of the document and follows the full path to the element. 0, using a different XML processing library that supports XPath 2. We will learn all methods of XPath axes with examples in the next tutorial. e. Start the session Mar 11, 2024 · Although Selenium’s default XPath engine is XPath 1. This XPath Locators Cheat Sheet is your go-to guide to make the most out of XPath selector for Selenium automation testing. Two types of Selenium XPath are . The different ways of finding the elements on a webpage using the Selenium XPath discussed here will be useful when you work in your real-time project. 1. XPath with Python. Xpath Checker is a Firefox add-on to automatically generate Xpath for a web element. We will also understand instantiating a WebDriver object to launch the web browser and work with the most frequently used methods like get(), findElement(), sendKeys(), click(), close() of the WebDriver class. Absolute XPath; Relative XPath; Absolute XPath . Absolute XPath is the simplest XPath in Selenium. Selenium automates browsers. Example - /html/form/input[1]. Syntax – driver. The syntax is: var xpathResult = document. Absolute XPath and Relative XPath. Jun 6, 2024 · Examples of using XPath locators in Selenium To demonstrate how XPath can be used in Selenium to locate web elements, consider an HTML page with a list of items. Our XPath tutorial includes all topics of XPath 2 min read . Feb 7, 2025 · Selenium Code Examples for Web Automation Testing. How to Handle Complex and Dynamic Elements in Selenium using XPath? Feb 14, 2025 · How to Find Element by Text using Xpath Selenium: Example. 0 Mar 17, 2025 · XPath tutorial provides basic and advanced concepts of XPath. Sometimes you may need to identify an HTML table using its row count. Just right-click a DOM element and copy the XPath. Dec 28, 2022 · The examples provided should help kickstart your testing with XPath in Selenium. Jul 10, 2023 · Absolute XPath – The XPath expressions created using absolute XPaths begin the selection from the root node. Here are two types of XPath available in selenium: 1) Absolute XPath. Xpath Functions. Let’s explore some practical use cases to illustrate how XPath can be used effectively. He wants only the nearest one which is the one with position()=1, so his xpath expression needs to be slightly amended to: Jan 23, 2017 · The button has a text of "Save" and there is nothing more unique in it's xpath, so I'm trying to write an xpath based on element's text. Jan 2, 2019 · Welcome to Selenium tutorial, today we will see how to write Dynamic XPath in Selenium because we can’t go ahead without XPath and CSS so let’s discuss XPath different methods in detail. It guides you the advanced concepts of Selenium test automation. Selenium - XPath to find sibling elements; Selenium - XPath for the next sibling element; Selenium - XPath for all the next following sibling elements; Selenium - XPath for the previous sibling element; Selenium - XPath for all the previous sibling elements; Form elements; Selenium - Submit Form; Input Text; Selenium - Xpath for input text field Feb 24, 2016 · Selenium XPath Examples. What are XPath axes. XPath is used to: Query or transform XML Jul 26, 2024 · Learning how to find web elements and writing dynamic XPath in Selenium manually may take a long time and a lot of practice. There may be times that while locating a particular web element using general attributes, there are elements that have similar properties, like the same name or the same class name. Here is a couple of very useful Add-ons that can assist in discovering the XPath of an element: xPath Finder - Plugin to get the elements xPath. While contains() can be used with any partial portion of the text or any partial portion of the attribute value XPath for sibling elements when element's id is given. XPath to locate a table using row count. The simplest XPath locator example in Selenium is to provide the absolute path of an element in the DOM structure. XPath Axes search different nodes in XML document from current context node. Jan 28, 2020 · Selenium will pick the first element in the path if there are multiple candidates for a given XPath when webdriver. There are lots of Python packages with support for XPath, lxml; Scrapy; Selenium; For the following examples, we are going to use Selenium with Chrome in headless mode. Absolute Path. Also Read: Arrays in Java and its implementation in WebDriver. Jun 28, 2019 · Writing Complex & Dynamic XPath In Selenium Through Various Methods Using Basic XPath This is the common and syntactical approach of writing the XPath in Selenium which is the combination of a tagname and attribute value. Oct 23, 2017 · That's just another option to build xPath locators. Aug 31, 2024 · Locating Strategies- (By XPath- Using Or) In this section, you will learn how to locate a particular web element by XPath- Using Or. Absolute XPath Relative XPath. XPath expressions define paths to navigate through a document's nodes. To help newbie test automation engineers, we have written this blog article with various XPath Examples for HTML Tables. net Tutorial for Beginners Part 1 How To Set Up Apr 12, 2025 · Web Table in Selenium. Moreover, XPath follows the XSLT(eXtensible Stylesheet Language Transformations) standard May 3, 2024 · How to use XPath in Selenium. Let us create locator for female radio button using xpath. Relative XPath: //input[@id = 'email'] Other example of Relative XPath are as follows: . In this post, we will learn how to automate web tables with Selenium Webdriver. Example of relative XPath: //button\[@id='submit'\] XPath Example: Here's an Feb 6, 2025 · What is XPath? XPath is a query language designed to extract and locate information within an XML or HTML document. Mar 11, 2024 · Best Practices for Using XPath in Selenium. For example, you know only the id of the web element, say myid, and you would like to get all the sibling elements of this element using XPath, then use the following code. It is an important strategy to locate elements in selenium. Locators are one of Selenium’s valuable features. If the element is written deep within the HTML code such that the number to use for the predicate is very difficult to determine, we can use that element’s unique attribute instead for Selenium get table element. Previous X-Unit Tutorial Episodes Introduction to XUnit. It's always tricky to fetch data from a web table using Selenium and when the table structure keeps changing every time on the basis of data to be shown then it becomes a more challenging task to automate it. The XPath is the language used to select elements in an HTML page. Feb 13, 2025 · XPath in Selenium is used to locate the elements when other locators wont work. These examples cover some basics, but in order to learn more, the following references are recommended: W3Schools XPath Tutorial. Tools and technologies used in this example are Java 1. It’s an expression language that is used to query or transform. What is XPath Web Locator in Selenium? XPath uses the path-like syntax that helps us identify and navigate the nodes found in XML and HTML documents. Relative XPath – The relative XPath expressions are a lot more compact and use forward double slashes ‘//’. Here is the Java program written in Eclipse for the same: Oct 1, 2021 · Apart from the syntax as mentioned above components, XPath in Selenium provides a few advanced concepts. Relative XPath. They enable us to locate web elements. Unlike Absolute XPath, which provides the full path from the root of the HTML document, Relative XPath offers more flexibility and simplicity. W3C XPath Recommendation. Let’s look at some examples of using XPath in Oct 22, 2024 · In this article, we'll cover how to use XPath with Python Selenium, complete with examples and best practices. XPath in Selenium is a foundational building block for creating a Selenium automation framework. Generally, normalize-space(String s) is a method in Xpath useful to remove any leading or trailing spaces in a Selenium - XPath to find sibling elements; Selenium - XPath for the next sibling element; Selenium - XPath for all the next following sibling elements; Selenium - XPath for the previous sibling element; Selenium - XPath for all the previous sibling elements; Form elements; Selenium - Submit Form; Input Text; Selenium - Xpath for input text field 5 days ago · Complete Link Text in Selenium – By. ; Dynamic tables: Data is dynamic i. Syntax to write the Attribute Based XPath: XPath in Selenium. Nov 19, 2024 · XPath in Selenium Explained. In this guide, we will explore XPath locators, delve into their essentials, syntax, types, and functions, and provide you with an exhaustive Selenium XPath Cheat Sheet. This will return the first name text box. In XPath, there are two methods for locating an element: absolute and relative. Java Mar 5, 2025 · In this tutorial, we will learn about how to find an element by XPath in Selenium with the help of examples. – kjhughes Commented Apr 22, 2018 at 16:19 In the previous article, I have practically demonstrated contains() XPath Function. Number of rows and columns are fixed. His solution was supposed to return all the ancestor foos. These Mar 5, 2025 · This comprehensive Selenium cheat sheet will guide you through the essential elements you need to know about Selenium, including its locators, commands, methods, and how to use Selenium with different programming languages like Python, Java, and C#. What is the profit of searching wrapper element: you can return it by method (example in java) and just build selenium constructions like: getGroupByName("Arcade Reader"). In this article, I am going to explain the next XPath Function known as starts-with() Difference between contains() and starts-with() XPath Functions. ) It will be displaying correctly at Front End (FE) but in DOM, it is in different way i. Selenium has 8 locators which include id, name, classname, XPath, CSS, linkText, partialLinkText and tag name which make our task easy to find elements. What is Chained XPath in Selenium? Chained XPath in Selenium is a technique for combining multiple XPath expressions to locate an element more precisely. Below are some of the main reasons why XPath is pivotal in Selenium: 1. The below code can be used to detect any element on a WebPage by XPath using Selenium in C# Familiarize yourself with the types of XPath in Selenium to improve element selection strategies; Types of XPath. It’s more flexible and resilient to changes in the page structure. . xpath (“ XPATH ”)) method is used. Apr 14, 2020 · XPath is the language used for locating nodes in an XML document. XPath Tutorial - with interactive examples. As HTML can be an implementation of XML (XHTML), Selenium users can leverage this powerful language to target elements in their web applications. In the real-world scenario, we need to filter the XPATH to extract the data. Absolute Xpath is a simple and direct way to find elements from the root node but if there are any changes made to the path of the element then that Xpath is failed it is a big advantage of the absolute path. d) Using Multiple Attribute. ∙ Relative XPath starts with //. Creating Xpath becomes a little simpler by using Xpath Checker. Now that we’ve covered the XPath basics, let’s start our XPath tutorial for Selenium with a range of examples for using XPath to select elements within an HTML document. XPATH, "xpath") Example – For instance, consider this page source: html Apr 1, 2025 · This Tutorial Explains XPath Axes for Dynamic XPath in Selenium WebDriver With the help of Various XPath Axes Used, Examples and Explanation of Structure: In the previous tutorial, we have learned about XPath functions and its importance in identifying the element. Mar 7, 2025 · Mainly there are two types of XPath that you can use in Selenium. If the parent element is known then the web element can be easily found or located that can use the sibling attribute of the Xpath expression in selenium webdriver. evaluate() document. Aug 28, 2018 · In this example we will discuss about the usage of normalize-space in Xpath. Nov 20, 2024 · Practical Examples of Using XPath in Selenium. There are two types of XPath that you can use. Click on the link to “View full example on GitHub” to see the code in context. XPath Axes are the methods used to find dynamic elements, which otherwise not possible by normal XPath method having no ID, Classname, Name, etc. containing uneven white spaces among words. Absolute XPath (Avoid If Jun 28, 2023 · Learn how to write dynamic and effective XPath locators for Selenium Webdriver projects. Use the shortest XPath expression possible to avoid brittle tests. The video explains cross browser testing using xUnit with practical examples. For this article, we’ll be using the Developer's Tools within the Chrome browser. Nov 16, 2024 · Single Slash mechanism is also known as finding elements using Absolute XPath. May 15, 2012 · document. Refer to this link to know details about these functions. If the elements to be tested cannot be found by general locators like ID, name, tag name, class, or other attribute, use the XPath locator. If you want to select the third item in a list with the class 'example', the XPath expression would be: Apr 1, 2025 · 30+ Best Selenium Tutorials: Learn Selenium With Real Examples; Selenium IDE Download Installation and Core Features Introduction; Selenium IDE Tutorial: IDE Commands with Examples on Firefox; How to Use Firebug for Creating Selenium Scripts – Selenium Tutorial #4; Selenium Locators: Identify Web Elements Using XPath in Selenium (Examples) Jun 1, 2023 · To write a dynamic XPath in Selenium, log into the website where the test will be done and find the XPath extension in the Chrome browser (without any plugin). However, writing robust Selenium locators comes from experience. 1 min read . Selenium Webdriver provides several methods for finding web elements using XPath expressions. As experts suggest, Relative XPath is more reliable than the Absolute XPath. The one-page guide to Xpath: usage, examples, links, snippets, and more. find("button[name='delete']"); or even simplify more Mar 27, 2025 · Using Chained XPath In Selenium. Sep 11, 2024 · XPath also called as XML Path is a language to query XML documents. For other methods of locating elements, see our guide on Finding Elements by Name . Mar 9, 2025 · Everything Selenium does is send the browser commands to do something or send requests for information. We will be demonstrating over 20 different XPath expressions in this section. Here’s an example: Apr 1, 2025 · Here are the Top 20 Ways to Write Ultimate XPATH for ANY Type of Web Element (XPATH will never be invalid): A web application is made up of different types of web elements such as a web element for a button to click on, input web element to type text, drop-down, radio buttons, etc. Jul 19, 2021 · XPath is one of the widely used web locators that is used to locate WebElements in the DOM. Attribute-Based XPath We locate a particular node in the DOM page by using the attribute. Move Code. Relative XPath B. In other words, it uses non-XML syntax that makes it flexible to address various parts of an XML document. find("button[name='settings']"); getGroupByName("Arcade Reader"). For example Apr 22, 2018 · XPath is bigger than Selenium, and JeffC's edit was entirely appropriate given that this question is about XPath itself, not any particular use of XPath in Selenium. Number of rows and columns are NOT fixed. These expressions either begin with the ‘/’ or the root node and traverse the whole DOM to reach the element. find_element(By. Examples of XPath in Selenium. evaluate() returns an XPathResult based on an XPath expression and other given parameters. For example, you know only the id of the web element, say my_id, and you would like to get all the next sibling elements of this element, that are followed after this element, using XPath, then use the following code. Dec 11, 2024 · XPath in Selenium is widely used to locate and interact with elements on web pages. Food Time Click to practice shadow dom inside iframe scenario If you find difficult to handle any scenario on this page, checkout the tutorial here on SelectorsHub Youtube channel and if you want to learn each concept in detail, you must take this course by Creator Sanjay Kumar Course Link Oct 1, 2021 · XPath Example: Usage of XPath functions and Axes in Selenium What are XPath Functions in Selenium? Sometimes while working in a dynamic web environment, it becomes challenging to locate a particular web element by using general attributes such as name, class, etc. Xpath Checker. Sep 30, 2018 · <anyTag> Make Selenium Easy </anyTag> (Inner text has more white spaces among words than normal. Using 2 days ago · By. Mar 5, 2025 · The example of a relative XPath expression of an element is as below. Selenium. XPath can locate any element on a page based on its ID, CSS Selectors, Name, TagName, ClassName, etc. Moreover, we can find a web element at a specified position if the locator's XPath has resulted in multiple elements. In Selenium testing WebDriver, XPath plays a pivotal role in locating elements on a webpage, especially when other locators like ID, Name, or Class are not sufficient. kxtj tnlu njyit zxylbr ydn zjse kvxtw znmzh mag wfgu iisap atxci kkn zkjie krfmlj