none
System.Windows.Automation cache request for optimal speed RRS feed

  • Question

  • I'm using the System.Windows.Automation namespace and setting up cache request for retrieving the bounding rectangle element details for all of these widgets (hyperlink, image, radiobutton, combobox, checkbox) with Internet Explorer. I am using the code below but not convinced I have set the cache correctly and I am setting up the elements collection properly. Everything works fine but my goal is optimal speed. I am using threading as recommended. Any comments gratefully received:

    AutomationElementCollection elements = null;
    AutomationElement element = AutomationElement.FromHandle(hwnd);
    Condition[] ieConditionArray = new Condition[5]
    {
        hyperlinkCondition, radioButtonCondition, comboBoxCondition, 
        checkBoxCondition, imageCondition
    };
    Condition ieCondition = new OrCondition(ieConditionArray);
    
    CacheRequest cacheRequest = new CacheRequest();                
    cacheRequest.Add(AutomationElement.IsControlElementProperty);
    cacheRequest.Add(AutomationElement.BoundingRectangleProperty);
    cacheRequest.TreeScope = TreeScope.Element;
    
    // Leave at the default AutomationElementMode.Full
    // cacheRequest.AutomationElementMode = AutomationElementMode.None;
    
    using (cacheRequest.Activate())
    {
        elements = element.FindAll(TreeScope.Descendants, ieCondition);
    }

    l
    • Edited by scocia888 Saturday, April 21, 2018 2:59 PM
    Saturday, April 21, 2018 2:58 PM

All replies