locked
Could not find Automation Element

    Question

  • Hello All,

    Iam trying to find  automation element for the particular component in Web apps developed using  ASP.Net .I could not find al the automation elements and Ids .I could see al l the properties using UIA2.0

    Please go through the below code. Appreciate your help !

    uSECASE 1:

    public static void  getRecursiveElements(AutomationElement parent)
    {
         
        AutomationElementCollection children,children1,children2;
      children = parent.FindAll(TreeScope.Descendants, Condition.TrueCondition);
      if (children != null && children.Count != 0)
          {
              for (int i = 0; i < children.Count; i++)
              {
                  //AutomationElement val = children[i].Current;
                  //getRecursiveElements(children[i]);
                  sw.WriteLine(children[i].Current.Name);
                  sw.WriteLine(children[i].Current.AutomationId);
                  sw.WriteLine(children[i].Current.LocalizedControlType);
                  //if (children[i].Current.Name == "Create/Edit Asset")
                  //{
                  children1 = children[i].FindAll(TreeScope.Descendants, Condition.TrueCondition);
                  if (children1 != null && children1.Count != 0)
                  {
                      for (int j = 0; j < children1.Count; j++)
                      {
                        
                          sw.WriteLine("ChildName1----->" + children1[j].Current.Name);
                          sw.WriteLine("ChildID----->" + children1[j].Current.AutomationId);
                        sw.WriteLine(children1[j].Current.LocalizedControlType);

                          children2 = children1[j].FindAll(TreeScope.Descendants, Condition.TrueCondition);

                         if (children2 != null&&children2.Count!=0)
                          {
                              for (int k = 0; k < children2.Count; k++)
                              {
                                  sw.WriteLine("ChildName2----->" + children2[k].Current.Name);
                                  sw.WriteLine("ChildID----->" + children2[k].Current.AutomationId);
                                 sw.WriteLine(children2[k].Current.LocalizedControlType);
                              }
                          }
                      }
                  }
                  // }
              }
      }
          sw.Close();
    }

    useCase 2:

     

     

      private AutomationElement WalkControlElements1(AutomationElement rootElement)
            {
                // Conditions for the basic views of the subtree (content, control, and raw) 
                // are available as fields of TreeWalker, and one of these is used in the 
                // following code.
                AutomationElement elment = rootElement;
                AutomationElement elementNode = null;
                if (elment == null) return elementNode;
              
                // your logic for condition ( this I don’t know what to write)
                //bool val = true;
                elementNode = elment.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Select Business Category Product"));

                if (elementNode != null)
                {
                    ///val = true;
                    return elementNode;
                }
                WalkControlElements1(TreeWalker.ControlViewWalker.GetFirstChild(elment));
                // Call for next sibling
                WalkControlElements1(TreeWalker.ControlViewWalker.GetNextSibling(elment));

                // Call for First child
              
                return elementNode;
            }

     

     

    Friday, August 30, 2013 10:41 AM

Answers

  • Hi Mohan,

    The Building Windows Store apps with HTML5/JavaScript forum is for discussion of writing Windows Store apps. For help with ASP.net apps please post in the forums on http://asp.net . For general help with writing accessibility clients please see the http://social.msdn.microsoft.com/Forums/windowsapps/en-US/home?forum=windowsaccessibilityandautomation forum.

    It isn't clear from your description if the problem is on the server side (does the web app expose the automation information you need) or the client side (can the automation client see the information). I would run Inspect.exe to examine the information provided by the web app. If Inspect cannot see what you need then you will need to update the web app. If Inspect can see the information then the problem is with the client's code. In that case you may have better results using the native automation API rather than the older .Net objects. See the UI Automation Overview and Guy Barker's UI Automation in C# samples for information on how to call the modern API from .Net.

    --Rob

    Friday, August 30, 2013 5:26 PM
    Moderator