Home > OS >  Selenium Webdriver Xpath id random
Selenium Webdriver Xpath id random

Time:11-24

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" 
 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" 
 
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

CodePudding user response:

In case the first part of the id is unique and stable as it seems to be, you can use XPath or CSS Selector to locate this element.
XPath:

browser.find_element(By.XPATH, "//span[contains(@id,'icm_widget_SelectorTabContainer_0_tablist')]")

CSS Selector:

browser.find_element(By.CSS_SELECTOR, "span[id*='icm_widget_SelectorTabContainer_0_tablist']")

CodePudding user response:

Try to use below xpath

browser.find_element(By.XPATH(contains(@id, 'icm_widget_SelectorTabContainer') and text()='Search');
  • Related