I’d assume that one of those hostile armies is in the other army’s territory, and that the attacking army would have some kind of strategic aim that could be predicted, and the defenders have a vested interest in seeking them out to do battle before they achieve it.
Also, I can’t imagine a medieval army is particularly easy to hide most of the time.