OriginalPostID-144422
Discussion posts and replies are publicly visible
Instead of relying solely on attributes like id or class, you can try to identify elements based on their text content. For example, in your case, you have a radio button with options "Yes" and "No." You could use a CSS selector or XPath that targets these radio buttons based on their labels.
// Example CSS selector WebElement radioButtonYes = driver.findElement(By.cssSelector("span.gwt-RadioButtonLabel:contains('Yes')")); // Example XPath WebElement radioButtonNo = driver.findElement(By.xpath("//span[@class='gwt-RadioButtonLabel'][contains(text(), 'No')]"));
Also, you can use relative XPath expressions (read here- mlops training) that are based on the known surrounding elements or structures. This can make your XPath more robust against changes in the HTML structure.
WebElement radioButtonYes = driver.findElement(By.xpath("//div[@class='aui-RadioButtonGroup']//span[contains(text(), 'Yes')]"));