I usually introduce myself by my first name and stick out my hand, thanking them for great service. Most of them automatically respond with their name. If the service was awful and there is another employee, I might ask another employee for the desired one's name. Other ruses that I have used is to say that I like to thank people for their work and I ask for their first name ... once I pointed at them and said, "Kurt? Charlie? We met, right? and he told me his name (Darrell)."
I have also said, "Can I have your name for a positive Yelp review?"
I have to confess that in very suspicious places, like bad-neighborhood cellphone outlets, there are definitely employees who will not give you their names. Most companies for whom I have worked will understand if you give a good description and say the nametag was obscured or unavailable, so be sure you capture height, hairstyle, glasses or not, and eye color.
Doing my best, every day