My point is that you are peeved with the cashier for talking to someone whilst supposedly serving you (or not) - fine, I get that... but leaving your stuff there for them to put back on the shelf only leaves you without your shopping, and someone else (usually not the cashier in question) putting your stuff back so you haven't got any kind of "payback" on them.
On the other hand, waiting to finally get served and then putting in a complaint about the cashier whilst leaving the store might be a useful alternative - CCTV could be checked to see how much they were talking/delaying things and what kind of attitude they were displaying (body language will speak volumes) and assuming the Management care about this sort of thing something could be done. If not then simply choose to shop elsewhere and they will have to take some form of action if enough people do it.