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