Use contains function:

driver.find_element_by_xpath("//span[contains(@id, 'jazz_ui_toolbar_Button_')]").click()

*UPDATE

If there are multiple element, you can use sequence [number] in the last xpath like this:

driver.find_element_by_xpath("(//span[contains(@id, 'jazz_ui_toolbar_Button_')])[1]").click()

Or use .find_elements:

elements = driver.find_elements_by_xpath("//span[contains(@id, 'jazz_ui_toolbar_Button_')]")
#elements[index].click()
elements[0].click()

The above refers to the first element.

Answer from frianH on Stack Overflow
🌐
TestGrid
testgrid.io › test automation › how to write and handle dynamic xpath in selenium [with tactics]
Dynamic XPath In Selenium [April 2026] | TestGrid
August 11, 2025 - In Selenium, there are two types of XPath. ... It is the most direct way to find the element, but the disadvantage of “absolute XPath” is that if the element’s path changes, that particular XPath fails. The critical feature of XPath is that it begins with a single forward-slash (/), indicating that you can select an element from the root node using Dynamic XPath.
🌐
BrowserStack
browserstack.com › home › guide › mastering dynamic xpath in selenium
Mastering Dynamic XPath in Selenium | BrowserStack
March 4, 2025 - However, when an element is dynamic and its attribute value changes frequently, XPath is the best choice for testers. To write XPath locators in Selenium, you have to use XPath expressions in the By.xpath() method to locate elements.
Discussions

How to handle dynamic xpath in selenium (python) - Stack Overflow
I tried using absolute xpath, no good. More on stackoverflow.com
🌐 stackoverflow.com
selenium - Handling Dynamic Xpath - Stack Overflow
The best choice is using full xpath instead of id which you can get easily via firebug. More on stackoverflow.com
🌐 stackoverflow.com
WebApp with dynamic xpath name
Not a direct solution to your issue but I just wanted to chime in and point out you should double check that you're using/copying the PSM-WebAppSample connection component and NOT the PSM-WebFormSample, I believe the webform one is deprecated and it's caused me some strange/unexplainable issues in the past More on reddit.com
🌐 r/CyberARk
4
2
October 16, 2020
Selenium Issue: Dynamic Popups with Changing XPath
if the popup always looks the same, you could search for the popup title and from there go to the child button More on reddit.com
🌐 r/webscraping
13
4
February 24, 2025
People also ask

What is XPath in Selenium and why is it used?

XPath (XML Path Language) is a query language used to locate elements in XML documents and HTML pages. In Selenium, XPath helps you find elements on a web page—especially when there are no unique IDs or names—by navigating the HTML structure using tags, attributes, and text.

🌐
testomat.io
testomat.io › home › xpath in selenium
XPath in Selenium: Syntax, Types, and Examples Explained
What’s the difference between absolute and relative XPath in Selenium?
  • Absolute XPath starts from the root (/html) and follows the full path to the element. Example: /html/body/div[2]/ul/li[3]/a. It’s fragile—changes in the page structure can break it.

  • Relative XPath starts from the middle of the document using // and doesn’t require the full path. Example: //a[@id='login']. It’s more flexible and preferred in most cases.

 

🌐
testomat.io
testomat.io › home › xpath in selenium
XPath in Selenium: Syntax, Types, and Examples Explained
How do you write an XPath in Selenium to locate an element by text?

You can use the text() function. For example:

xpath //button[text()='Submit']

This finds a element with the visible text “Submit”. You can also use contains() for partial matches:

xpath //button[contains(text(),'Submit')]

🌐
testomat.io
testomat.io › home › xpath in selenium
XPath in Selenium: Syntax, Types, and Examples Explained
🌐
Software Testing Material
softwaretestingmaterial.com › home › selenium › how to write dynamic xpath in selenium webdriver
XPath in Selenium WebDriver Tutorial: How to Find Dynamic XPath?
XPath axes are the methods used to find dynamic elements that would otherwise be impossible using standard XPath methods, which do not include an ID, Classname, Name, or other identifiers.
Published   June 21, 2025
🌐
Virtuoso QA
virtuosoqa.com › post › dynamic-xpath-in-selenium
Dynamic XPath in Selenium Explained With Examples
Dynamic XPath enables Selenium to locate elements with changing attributes, but comes at a cost: complex expressions, performance overhead, and maintenance burden.
🌐
Medium
nuwan-abeywickrama.medium.com › selenium-with-dynamic-elements-how-to-handle-dynamic-xpath-id-640a9544bd3d
Selenium with Dynamic Elements. How to Handle Dynamic XPath & ID? | Medium
March 25, 2025 - Debugging Is Key I spent time logging the toString() output of By objects to understand how Selenium interprets them. It helped me perfect this solution. Don’t be afraid of complex systems. If you’re new to Selenium or test automation, here’s some advice. Start with Static Locators Practice with simple IDs or XPaths before tackling dynamic ones.
🌐
Testomat
testomat.io › home › xpath in selenium
XPath in Selenium: Syntax, Types, and Examples Explained
3 weeks ago - XPath in Selenium with syntax, functions, dynamic XPath, and examples. Write, find, and use absolute and relative XPaths in automated software testing.
Address   Ul. Koszykarska 27b-26, Kraków
Find elsewhere
🌐
Software Testing Help
softwaretestinghelp.com › home › selenium automation › xpath functions for dynamic xpath in selenium
XPath Functions For Dynamic XPath In Selenium
April 1, 2025 - This article explains how to use XPath Functions contains(), starts-with() and text() with attribute and text to uniquely identify the elements.
🌐
Bird Eats Bug
birdeatsbug.com › blog › dynamic-xpath-in-selenium
How to Use Dynamic XPath in Selenium: A Complete Guide | Bug Tracking Blog @ Bird Eats Bug
November 6, 2025 - Inefficient locators can slow down execution and increase the risk of failures, especially in complex or dynamic web pages. The following practices help create faster and more maintainable XPath expressions: Prefer relative XPath: Use relative paths that begin with // instead of absolute ones that start from the root. Relative XPath adapts better to structural changes and executes faster. Avoid wildcards and redundant axes: Refrain from using //* or unnecessary traversal axes. These cause Selenium to search the entire DOM, which reduces efficiency.
🌐
Automation
learn-automation.com › home › how to write dynamic xpath in selenium
How to write Dynamic XPath in Selenium Webdriver using Different Method
December 16, 2020 - Yes, you can use array for that. Take all locators wrt browse button inside an array and call its click action based on index. Or you go for dynamic xpath. ... Thanks for your comments. ... Hello Mukesh, Thanks for uploading such a nice and useful selenium webdriver inforamtion.
🌐
AddWeb Solution
addwebsolution.com › home
Dynamic XPath In Selenium WebDriver A Complete Guide
June 10, 2024 - Dynamic XPath is also called as custom XPath and it is one way to locate elements uniquely. It is used to locate exact attributes or decrease the number of matching nodes/results from a webpage and following XPath expressions can be used for ...
🌐
SWTestAcademy
swtestacademy.com › home › xpath in selenium with all tactics and examples
Xpath in Selenium with All Tactics and Examples
June 28, 2023 - It is a very handy XPath Selenium locator, and sometimes it saves the life of a test automation engineer. When an attribute of an element is dynamic, you can use contains() for the constant part of the web element but also use contains() in any condition when you need.
🌐
Quora
quora.com › How-do-I-write-Dynamic-XPath-in-a-Selenium-WebDriver
How to write Dynamic XPath in a Selenium WebDriver - Quora
Answer (1 of 9): XPath in Selenium helps an individual find out solutions in locating elements when the standard processes do not work. When to use which is important when it comes to different complexities of the DOM structure and the functional ...
🌐
Thinkitive
thinkitive.com › home › write dynamic xpath for test automation with selenium webdriver.
Write Dynamic XPath for test automation with Selenium WebDriver.
January 8, 2026 - Master dynamic XPath in Selenium WebDriver for precise web element location. Boost test automation efficiency with XPath and debunk myths.
🌐
Sauce Labs
saucelabs.com › home › blog › getting started with xpath in selenium
How To Use XPath In Selenium Tutorial With Examples | Sauce Labs
June 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).
🌐
Testmu
testmu.ai › testmu ai › blog › how to use xpath in selenium [xpath tutorial] | testmu ai
How to Use XPath in Selenium [XPath Tutorial] | TestMu AI (Formerly LambdaTest)
January 11, 2026 - Dynamic or Nested Elements: XPath efficiently handles dynamic, deeply nested, or component-based elements that standard locators struggle to access or identify correctly. Advanced Logic Support: XPath enables conditional matching, partial attribute ...
🌐
Guru99
guru99.com › home › selenium › xpath in selenium: tutorial
XPath in Selenium: Tutorial
XPath in Selenium includes several methods such as Contains, AND, Absolute XPath, and Relative XPath to identify and locate dynamic elements based on various attributes and conditions.
Published   December 26, 2025