How to deal with the object for which xpath is always changing

Example object’s xpath (Selected locator):
id(“mat-menu-panel-40”)/div[@class=“mat-menu-content ng-tns-c25-109”]/button[@class=“mat-focus-indicator mat-menu-item ng-tns-c25-109 ng-star-inserted cdk-focused cdk-mouse-focused”]
reload the page
id(“mat-menu-panel-41”)/div[@class=“mat-menu-content ng-tns-c25-109”]/button[@class=“mat-focus-indicator mat-menu-item ng-tns-c25-109 ng-star-inserted cdk-focused cdk-mouse-focused”]
reload the page
id(“mat-menu-panel-44”)/div[@class=“mat-menu-content ng-tns-c25-109”]/button[@class=“mat-focus-indicator mat-menu-item ng-tns-c25-109 ng-star-inserted cdk-focused cdk-mouse-focused”]
and so on…

You can rewrite it to

//*[starts-with(@id,“mat-menu-panel-”)]/div[contains(@class,“mat-menu-content')]/button[contains(@class,“mat-focus-indicator") and contains(@class, "mat-menu-item") and contains(@class, "ng-star-inserted") and contains(@class, "cdk-focused") and contains(@class, "cdk-mouse-focused”)]

Thanks, It is working now :slight_smile: