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 OverflowHow to handle dynamic xpath in selenium (python) - Stack Overflow
selenium - Handling Dynamic Xpath - Stack Overflow
WebApp with dynamic xpath name
Selenium Issue: Dynamic Popups with Changing XPath
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.
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.
How do you write an XPath in Selenium to locate an element by text?
You can use the text() function. For example:
//button[text()='Submit']
This finds a element with the visible text “Submit”. You can also use contains() for partial matches:
//button[contains(text(),'Submit')]
Videos
you can try using contains() or starts-with() in xpath,
above xpath can be rewritten as follows,
Driver.findElement(By.xpath("//*[starts-with(@id,'INQ')]/div[2]/tr/td/div/div[3]/div")).click();
if you can post more of your html, we can help improve your xpath..
- moreover using such long xpath's is not recommended, this may cause your test to fail more often
for example,if a "new table data or div" is added to the UI, above xpath will no longer be valid
- you should try and use id, class or other attributes to get closer to the element your trying to find
- i personally recommend using
cssSelectorsoverxpath
you can use many methods, use implicity wait;
driver.findElement(By.xpath("//*[contains(@id,'select2-result-label-535')]").click();
driver.findElement(By.xpath("//*[contains(text(), 'select2-result-label-535')]").click();