Bus tickets versus passes
If you travel a lot, you will be better off with a rail pass. Most of these passes are actually "public transport passes", and also cover buses. Other passes cover buses for free, so you don't need a ticket. Some passes offer a discount, so you need to purchase a discounted bus ticket.
Where to buy tickets?
If you don't have a pass for unlimited traveling, you will need to buy a ticket. In most cases you are supposed to buy a ticket before you board the bus. You can do so from the ticketing machine, a ticket office at a train or bus station, or online through the timetable. Some buses have an on board ticketing machine. In all such cases the driver does not sell or even check tickets. Tickets will be check randomly by other staff. Buses operating like this are labelled with a yellow icon in the shape of an eye.
In rural areas without machines and ticket offices, you can buy a ticket from the driver.