I don't believe anything is simple, or black and white - self esteem and ego is sensitive, fragile, selfish, fucked up thing, and people do terrible things they end up being ashamed of and which causes others pain.
I've seen it - Friend 1 being a total train wreck in relationships, cheating and being cheated on ad infinitum, and Friend 2 being cheated on over 25 times by the first husband - and in my opinion, it is all about validation. The person that strays is looking for validation that they are worthwhile, attractive, and "enough". Where self esteem is poor, they'll get that validation anywhere they see the slightest hint of it, particularly if they are not getting it in their own lives right now. Some people can never get enough validation, like a drug.
I'm happily married and wouldn't cheat, but I still get a little lift from being flirted with, same as my DH does. Presumably a person brave/stupid/numb/empty enough to act on it takes it a step further and further until eventually they box off their integrity and start stuffing body parts into one another.
With one exception, all the people I've known who have cheated, or the person who has cheated on them, is wholly lacking in self worth. The one exception was tied up in a terrible trauma.
On the other hand, maybe all people really are just arseholes?