most of the players including me experience this problem occasionally yet it is still frustrating. the best solution I can think of so far is by having no selected troops when searching and just press the portrait of the desired troop when you're ready ( just like when you are switching troops in a battle)

