Speed up clicking a sequence of buttons

14 views
Skip to first unread message

Dumitru Daniel

unread,
Apr 7, 2025, 7:24:37 AMApr 7
to TestStack.White
Hi,

I'm trying to automate pressing a sequence of 10 buttons (type is Panel) in this case, and it's driving me a bit mad because sometimes it's really fast when i find all 10 buttons, but sometimes i only find 2-3 buttons, and it takes a really long time, see my results below:
  • If I use Window.Get(SearchCriteria.ByAutomationId... , it takes
    • [2s] if I find the button 
    • [23s] if I don't find the button
  • If i use ```var dPanes =Window.GetMultiple(SearchCriteria.All) .OfType(Panel) .Where(pane=>pane.Visible) .ToDictionary(p => p.AutomationElement.Current.AutomationId, p => p)``` , and use ```dPanes.TryGetValue(autoId, out var paneButton)``` to get the button, it takes
    • [11s] if i find the button
    • [9s] if i don't
Is there a way to decrease the search wait time, or retry times, temporarely in this case, so i can run the sequence faster? 

Any advice is appreciated!

Thanks,
Daniel

mhetz...@gmail.com

unread,
Apr 7, 2025, 3:35:32 PMApr 7
to TestStack.White
I've had issues with windows automation and elements sometimes taking a while to find.
Unfortunately sometimes it can be the fault of teststack white itself because it has a lot of waiting for "ready" states built into its functions
For myself, I've had to actually dump TS White for a previous project and just write my own simple TSW-like framework wrapping the Windows Automation libs.

Are the buttons all of type Button or Pane?
If you are going a route where you, find 1 button -> click -> find next and repeat . . .
     is it possible that clicking buttons cause the parent window to update/change?

Do you find that it's the same elements causing the issues every time or does it seemingly happen randomly?

Have you tried treating the controls as generalized UIItems and locating them as such with minimal criteria first - just to get a quick list, then iterate over the list for what you need?

If all else fails . . . you can just goose it and find the first button/item, then figure out the tab order of the elements and send tabs, clicks, etc.

Also, maybe look into using the TreeWalker to find elements throw the raw element tree (the tree structure that appears in your inspect tool)
Not the functions below necessarily but maybe something customized for what you need.

public static T GetNextSibling<T>(this IUIItem thisItem) where T : IUIItem { var parent = TreeWalker.ControlViewWalker.GetNextSibling(thisItem.AutomationElement); var uiItem = new DictionaryMappedItemFactory().Create(parent, thisItem.ActionListener); return (T) UIItemProxyFactory.Create(uiItem, uiItem.ActionListener); } public static T GetPreviousSibling<T>(this IUIItem thisItem) where T : IUIItem { var parent = TreeWalker.ControlViewWalker.GetPreviousSibling(thisItem.AutomationElement); var uiItem = new DictionaryMappedItemFactory().Create(parent, thisItem.ActionListener); return (T) UIItemProxyFactory.Create(uiItem, uiItem.ActionListener); }


Reply all
Reply to author
Forward
0 new messages