A gripper device mountable on a robot arm (10) of a milking robot (2) provided for automatically attach teat cups (5) to the teats of a milking animal, the gripper device comprises an electromagnet (6) for gripping teat cups made of a magnetic material, the electromagnet including a coil (31) feedable with a current and a core (33) of a magnetic material arranged at least partly within the coil; and a support structure (7) for holding the electromagnet. The core comprises two end portions (33a-b) in a single face of the electromagnet, wherein the two end portions constitute different poles of the electromagnet, and are shaped to be engagable with each of the teat cups in a close fit.