To identify an element with dynamic id
e.g. #tab-t0-1 where 0 is a dynamic number and everything else is static you can use cssSelector with the following wildcards :
-
^ : To indicate an attribute value starts with
-
$ : To indicate an attribute value ends with
So the most granular locator would include the strategy to lookout for the initial letters i.e. tab-t and the ending letters i.e. -1 and should be :
[id^='tab-t'][id$='-1']
References
You can find a couple of relevant detailed discussions in:
- Java Selenium webdriver expression finding dynamic element by ccs that starts with and ends with
- How to click a dynamic link with in a drupal 8 website using xpath/css selector while automating through Selenium and Python
- Finding elements by CSS selector with ChromeDriver (Selenium) in Python