Forum Discussion

iainihoey's avatar
11 years ago

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

  • TanyaYatskovska's avatar
    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


    ...

    • bkirkendall's avatar
      bkirkendall
      New Contributor

      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);

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        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".