Ask a Question

Obtaining AutomationId from WPF applications

iainihoey
Not applicable

Obtaining AutomationId from WPF applications

Hi,



I am testing a WPF application, and I am unable to use the AutomationId to control anything.  This has been discussed before here:



http://smartbear.com/forums/f81/fp11/t73357/using-automation-id-to-identify-objects



But the solution given does not appear to be working for me.  The original solution is:




Set AutomationIdProperty = p.AppDomain"Automation_ID_Sample.exe").dotNET.System_Windows_Automation.AutomationProperties.AutomationIdProperty


  AutomationID = MyObject.GetValue(AutomationIdProperty)


  Log.Message(AutomationID)



I have updated this to:




Sub get_id_test()


  Dim SV, AutomationIdProperty


  Set SV = Sys.Process("myApp")


  Set AutomationIdProperty = AppDomain("SV").dotNET.System_Windows_Automation.AutomationProperties.AutomationIdProperty  


  AutomationID = WPFObject.GetValue(AutomationIdProperty)


  Log.Message(AutomationID)  


End Sub



But it fails with: Type mismatch: 'AppDomain'



Can anyone provide assistance on this?  Is there an easier way to do this in TC9.2?  The first solution was posted nearly 3 years ago, I would have thought a solution would exist without writing a script...

3 REPLIES 3
TanyaYatskovska
SmartBear Alumni (Retired)


Hi Iain,


 


You need to call AppDomain from the tested process:


...


Set SV = Sys.Process("myApp")


Set AutomationIdProperty = SV.AppDomain("myApp.exe").dotNET.System_Windows_Automation.AutomationProperties.AutomationIdProperty


...

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



In my case I am interested in the VerticallyScrollable property of a UIAutomation object for a WPF application. I tried modifying the sample provided in Tanya's post after proving I could successfully obtain the AutomationID. However, I am sure I am making an obvious mistake:

 

(Using JavaScript...)

 

var SV, AutomationIdProperty, AutomationID;
SV = Sys.Process("MyApp");


AutomationIdProperty = SV.AppDomain("MyApp.exe").dotNET.System_Windows_Automation.AutomationProperties.AutomationIdProperty;

AutomationID = MyWPFObject.GetValue(AutomationIdProperty);
Log.Message(AutomationID);   //Success!!

 

AutomationIdProperty = SV.AppDomain("Zetta.exe").dotNET.System_Windows_Automation.ScrollPattern.VerticallyScrollableProperty;
AutomationID = MyWPFObject.GetValue(AutomationIdProperty); //Fails here with error: "The parameter is incorrect"

Log.Message(AutomationID);

First of all... this is a 5 year old post... so, who knows what may have changed technology wise since then. 🙂

 

That said...  In your code, what is returned as the AutomationIDProperty for VerticallyScrollableProperty?  The code that Tanya posted is intended to bring back the automationID which, IIRC, is an integer value or string (not sure which) to be used for identifying the object.  VerticallyScrollableProperty is a different thing entirely and may not return as a type that can be used in "GetValue".  Double check what is returned and see if a conversion needs to be done before you can use it in "GetValue".


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: