My experience agrees with janettravels44: I've recently returned from 89 days in Spain, and I nearly always bought my bus tickets shortly before departure. That's really your only choice if you're making a multi-leg trip on different bus lines.
Just once or twice I had to wait for the second bus because the first was sold out. A bigger issue is that you can't predict how long it will take to get through the line. Unfortunately, you can't necessarily show up at the bus station at just any old time to buy a ticket. it's common for a company's ticket window to be open only when there's an imminent bus departure. If there's a gap in the schedule (over the lunch break, for example), the window is not likely to be staffed.
You might run into special situations (fiestas, etc.) that increase demand and make advance purchase prudent. I know the Madrid-Toledo buses are heavily used. I think Rick specifically mentions buying the Toledo-Madrid leg ahead of time to be sure you get back to Madrid (if that's where you're sleeping).
Someone on a shorter trip would very reasonably be more concerned about getting on the first-choice bus than I was.
For some itineraries there's a significant variation in time and/or cost, so at least checking out the schedules ahead of time is worthwhile. Some bus companies, including the large ALSA, have vending machines that are easy to use (English-language option) and will print their schedule for your selected destination. I was always more comfortable with that information in hand.
I had no trouble using my chip-and-signature credit card in the bus-ticket machines. I think I was sometimes asked for my ZIP Code (as at some gas pumps in the US).