Selenium WebDriver scenarios to locate elements due to dynamic ID changes in an Angular application
I'm working with an scenario with Selenium WebDriver where it struggles to locate elements in my Angular application because the IDs of these elements change dynamically every time the page is loaded. I've tried using various locator strategies such as XPath and CSS selectors, but they tend to unexpected result as the IDs are not predictable. For example, the HTML might look like this: ```html <div id="dynamic-id-12345" class="my-element">Click me!</div> ``` I initially tried this XPath to locate the element: ```python my_element = driver.find_element(By.XPATH, "//div[contains(@class, 'my-element')]" ) ``` However, when the page reloads, the ID changes to something like `dynamic-id-67890`, causing the previous locator to unexpected result. I've also attempted waiting for the element to become visible using WebDriverWait: ```python from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class, 'my-element')]") ``` But I still encounter `NoSuchElementException`. I also considered using a more stable attribute like a class name or a data attribute, but the class can also change. Has anyone faced a similar scenario? What strategies can I employ to reliably locate these elements without relying on their dynamic IDs? Any help would be greatly appreciated! Is this even possible?