Ask them what they prefer - If the touching is a problem, ask them what you should do. Let them tell you what do to:
Hi, you told me not to touch you, and I won't touch your headphone (again, sorry about that), but I'm not really sure how to get your attention, what would you prefer?
Wave - We just wave, depending on where you are related to the person. Try to aproach from the front or side. If you come from behind, try a little curve so you still come from the side. This is a very 'light' method and rarely results in a startle. It also allows the person to respond something like "one moment please". Don't do this right next to the person. You can do this from a small distance, to about a meter away from the person.
Send a message - We use Slack, but if you have some kind of message service you could use that. They can read the message, often in the notification, and respond accordingly. This also allows you to ask the question directly, or say what it's about "Got a moment to talk about X?".
Stand next to them - You could just stand next to them, about 1 to half a meter next to them. Their peripheral vision should see you and grab your attention. When they notice you, they could take of their headphone. Be sure to not stand too close, as someone suddenly being in your personal space can startle you very easily.
Tap on the chair/desk - Just a simple *tap tap* will suffice. This is an annoying option, but sometimes it's handy to do so. The other people in the office might be less interrupted by this.
A simple light tap on the shoulder/back - Not a full touch, but a simple one finger tap. People are sensitive, a light touch will grab their attention.
Ask them what they prefer - If the touching is a problem, ask them what you should do. Let them tell you what do to:
Hi, you told me not to touch you, and I won't touch your headphone (again, sorry about that), but I'm not really sure how to get your attention, what would you prefer?
DO NOT GRAB THEIR HEADPHONE. I would respond angrily as well, as you are suddenly touching me, disturbing my focus and possible hurt me. When you wear headphones for a while, ears often get a little more sensitive because the constant pressure.