In these cases you have three possibilities (assuming the wiring is good).
1. The solenoid (starter relay) is receiving current from the key switch but is not engaging properly or consistently. To check this component, bypass it. To bypass it use one side of a jumper cable. Clip to the positive of the battery with one end of the jumper cable (red). Hold to the large input wire on the starter with the other end of the same jumper cable (red). This should cause the starter to turn over strongly. If so, replace the solenoid.
2. If you try the above scenario 3 to 6 times and find the starter turns over inconsistently, or at times does not turn over at all, you may have flat spots on the starter. In this case you will have to replace the starter (this is the least likely scenario).
3. BEFORE you consider either of the above, consider the battery. This is an easy check if you have a simple volt meter. It's much better to have an old fashioned needle meter rather than a digital. The needle is more sensitive, much quicker, and makes a clearer diagnostic tool. But not to worry, a digital still works (sometimes the results are not as clear).
- Set the meter to DC Volts
- Attach the red and black leads of the meter to the positive and negative posts of the battery. Most modern day meters don't care if the polarity is correct or not. However, if you have a needle meter, best to put the positive of the battery with the red wire of the meter; otherwise the needle will not be happy with you.
- Note voltage. It should read above 13 volts if the battery is good and fully charged.
- Crank the engine while keeping your eyes on the meter. The meter should not fall much below 11 Volts. If it falls below 10 volts or worse yet below 9 volts, the battery has a bad cell or two. Replace the battery, charge it, and repeat the test.
- If the solenoid just rapidly clicks watch the meter needle.
- If the meter needle rapidly jumps up and down below 10 volts, back to 13, below 10, back to 13 then it's more likely you have a bad starter.
- If the needle simply seems to vibrate a little you more likely have a bad solenoid. Refer to steps 1 and 2.
- If the engine starts, rev it up and watch the meter.
- If the charging system is working the voltage on the meter should quickly rise above 12 or 13 volts.
- If it rises up strongly towards the 14 volt range this indicates the charging system of the machine is working.
- If it plays around down near 12 volts you are reading the recovered voltage of a good battery, but the charging system is not working.
- If it simply stays below 11 volts, the battery and the charging system are both suspect. Replace the battery first. Fully charge it, and then repeat the tests before worrying about the charging system.
I can't suggest any parts numbers because you did not include the very important Make/Model/Year. However, these general instructions will work for most riding lawn and garden tractors.