I would presume that the caster knows precisely what to target prior to casting the spell. Otherwise they wouldn't know what they were dispelling. All it takes is a reaction and an Arcana check to determine what spell is being cast, after all. Furthermore, spells like detect magic would sidestep the need to identify which was being affected in the first place: it would simply be apparent to the caster.