Plant secondary metabolites (PSM) are one of the promising options to control gastrointestinal nematodes in sheep and goats. The objective of this study was to assess the abilities of sheep and goats to self-medicate with tannin-rich sainfoin (Onobrychis viciifolia) (SF) when infected with gastrointestinal nematodes, using a cafeteria and an operant conditioning trial. Hypotheses were that parasitized (P) lambs and goat kids would show greater intake and preference for SF than their non-parasitized (NP) counterparts, that kids would eat more SF than lambs (due to their lower resistance against parasites and their greater ability to consume PSM), and that SF intake would increase over time for P animals. We used 20 female kids and 20 ewe lambs aged 3 months. Half of the animals per species (n = 10) were experimentally infected with 170 L3 larvae of Haemonchus contortus/kg of BW (P). The other half were free from parasites throughout the study (NP). Five weeks after infection, animals were exposed to a 24-day cafeteria trial (three 8-day periods) offering a free choice between two legume pellets: SF (3.8% condensed tannins) and alfalfa (ALF, Medicago sativa; no tannin). Subsequently, animals were involved in an operant conditioning trial of two 4-day long sessions, to assess in short-term tests their motivation to walk for a SF reward when offered in choice with freely available ALF. In the cafeteria trial, SF preference was greater in kids than in lambs, particularly in the first two periods. We did not observe a greater preference for SF in P animals, which was even greater in NP animals for periods 1 and 2. Sainfoin intake increased through periods for P animals, which led to similar SF preferences for all groups during period 3. In the operant-conditioning trial, motivation to get the SF reward was similar between P and NP animals. These results support the hypotheses that goats are more willing to consume tanniferous feeds than sheep, and that P animals increased SF intake through time. However, the emergence of a curative self-medicative behaviour was not supported, as P individuals did not show greater SF intake, preference, nor a greater motivation to get SF than NP animals, regardless of animal species. These findings are discussed with previous results and some explanations are presented.