Search code examples
pythonseleniumgoogle-chromewebdriver

Selenium Webdriver Xpath id random


I have a problem, when I look for the id of an xpath it changes every time I enter the web

how can i use selenium webdriver python browser.find_element(By.ID,) if the id changes every time I consult it

first

<span data-dojo-attach-point="containerNode,focusNode" 
class="tabLabel" role="tab" tabindex="0" 
id="icm_widget_SelectorTabContainer_0_tablist_dcf42e75-1d03-4acd-878c-722cbc8e74ec" 
name="icm_widget_SelectorTabContainer_0_tablist_dcf42e75-1d03-4acd-878c-722cbc8e74ec" 
aria-disabled="false" 
title="" 
style="user-select: none;" 
aria-selected="true">Search</span>

second

<span data-dojo-attach-point="containerNode,focusNode" 
class="tabLabel" 
role="tab" 
tabindex="0" 
id="icm_widget_SelectorTabContainer_0_tablist_c9ba5042-90d2-4932-8c2d-762a1dd39982"
name="icm_widget_SelectorTabContainer_0_tablist_c9ba5042-90d2-4932-8c2d-762a1dd39982" 
aria-disabled="false" 
title="" 
style="user-select: none;" 
aria-selected="true">Search</span>

try with


browser.find_element(By.XPATH
browser.find_element(By.ID
browser.find_element(By.NAME

same problem, the id changes


Solution

  • Try to use below xpath

    browser.find_element(By.XPATH(//span[contains(@id, 'icm_widget_SelectorTabContainer') and text()='Search']);