How to convert from AutomationElement of uiautomation library to AutomationElement of flaui library?

lf l 0 Reputation points
2024-04-25T14:30:02.33+00:00

How to convert an object ele of type **AutomationElement **defined by Microsoft's uiautomationg library(uiautomation) to a flauiEle object of type **AutomationElement **defined by the flaui library?

Both uiautomation library and flaui library are for automating the processing of windows desktop windows and their child controls. flaui is a wrapper and optimisation of uiautomation, so then both libraries define the AutomationElement class, just with the same class name. So how do they convert to each other?

Here's my c# code:

System.Windows.Automation.AutomationElement ele = System.Windows.Automation.AutomationElement.FromHandle(handle);//handle is a window handle
UIA3Automation uiauto3 = new UIA3Automation();
FlaUI.Core.AutomationElements.AutomationElement flauiEle = uiauto3.WrapNativeElement(ele);//flaui has this conversion method, but the code throws an exception.
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,277 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 48,576 Reputation points
    2024-04-25T15:05:55.71+00:00

    Just because 2 types share the same name don't make them the same type. The runtime uses the fully qualified name which includes the assembly so if you have type A in assembly A and you copy that type verbatim to assembly B and then load both A.A and B.A are 2 completely different types and are not interchangeable. This is by design. The only real way to make 2 different types look the same is to use an interface that they both implement.

    Given your question is about taking something from MS and getting it to work in a third party library I would recommend you post your question over in the library's Github page. They better understand how their library works and what you might be able to do to get this to work, if it is possible.

    0 comments No comments