I haven't seen any president being the best person for the job.
Obama won, because he ran flawless campaigns. Greatly reduced the amount of dirt that can be dug up. Any dirt that was, was treated well and marginalized.
2008 - People were tired of Bush, so any democrat had a chance. McCain, was too old, so people needed to judge the VP candidate as well, and Palian was just the worst pick you could make. For a candidate who needed to push a moderate campaign.
2012 - Romney failed to make himself genuine. Being very conservative for the primary, then trying to seem moderate for the main election just didn't work.
Sure being black helped the democrat party solidify a base who often had low voter turnout to vote, as well a lot of people wanted to see things differently. But all in all it was about how good of a marketing campaign it was.