I am writing Automation Test Scripts for Appian Screens using Selenium and Cucum

I am writing Automation Test Scripts for Appian Screens using Selenium and Cucumber. In the Screens, there are components like Date Field, Radio Button, Check boxes. Facing Issues to find a unique identifier for these components.Tried using Id, ClassName, XPath, but it didn’t work.Issue is that when the Appian screen is developed, the components do not have any identifier unlike JSP pages. These components when rendered on a browser, it converts to html.When html didn’t find any identifier, it creates a new identifier each time. So the identifier is not constant. ClassName is same for all the similar components. XPath is not uniquely traversing to the component. Consider a Radio Button which has Yes and No as an Option HTML Code : <div class="GG51K-MDGB"><div class="aui_FieldLayout_InputContainer"><div class="aui-RadioButtonGroup"><span class="gwt-RadioButto...

OriginalPostID-144422

OriginalPostID-144422

  Discussion posts and replies are publicly visible

Parents
  • 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')]"));

Reply
  • 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')]"));

Children
No Data