Skip to content

Commit

Permalink
Refactor UiaElementModel ID generation
Browse files Browse the repository at this point in the history
Removed dependency on automation ID for UiaElementModel instances. Now, each instance receives a unique ID composed of "element-" followed by a newly generated GUID, ensuring uniqueness and easy identification.
  • Loading branch information
gravity-api committed Jul 2, 2024
1 parent 271246c commit 0fc9fbb
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/Uia.DriverServer.Extensions/AutomationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,6 @@ public static UiaElementModel ConvertToElement(this IUIAutomationElement automat
return default;
}

// Get the automation ID of the element.
var automationId = automationElement.CurrentAutomationId;

// If the automation ID is null or empty, generate a new GUID as the ID; otherwise, use the automation ID.
var id = string.IsNullOrEmpty(automationId)
? $"{Guid.NewGuid()}"
: automationElement.CurrentAutomationId;

// Create a new LocationModel and set its properties based on the element's bounding rectangle.
var location = new RectangleModel
{
Expand All @@ -383,7 +375,7 @@ public static UiaElementModel ConvertToElement(this IUIAutomationElement automat
// Create and return a new ElementModel with the ID, UI Automation element, and location.
return new UiaElementModel
{
Id = id,
Id = $"element-{Guid.NewGuid()}",
UIAutomationElement = automationElement,
Rectangle = location
};
Expand Down

0 comments on commit 0fc9fbb

Please sign in to comment.