Search code examples
c#coded-ui-tests

How to identify an element for dynamically changing element in coded UI


Page Inspect HTML

The numbers keep changing whenever we perform an action. I have tried the following and it still does not work

HtmlControl clickOnObjectivesCatg = new HtmlControl(bw);
            clickOnObjectivesCatg.SearchProperties.Add(HtmlControl.PropertyNames.Id, "accordiongroup-5856-5055-tab", PropertyExpressionOperator.Contains);
            Mouse.Click(clickOnObjectivesCatg);

Solution

  • Try this:

    var control = new HtmlControl(bw);
    control.SearchProperties.Add(HtmlControl.PropertyNames.Id, 
        "accordiongroup", 
        PropertyExpressionOperator.Contains);
    

    I think your problem is yours is checking if the control contains the precise ID, whereas you need to be only checking for the sub string if the number changes.

    If you want to make this more reliable I would also suggest adding other search properties.