UGH. [snip]
Internet provides a lot of info, once you filter through the bullshit ad stuff. Incumbents have a voting record, which is public, if occasionally hard to actually
get at, and related political history. If challengers don't have previous political positions, you can look at job history and organizational affiliations (and occasionally campaign contributions), which is again usually public if hard to find. There's a paper trail, basically -- 'net makes it a bit easier to get at these days, but there's physical records laying around... somewhere. Newspapers, court rooms, city hall etc., so forth, so on. You can put your feet on the pavement and find out yourself if you've got the time (and occasionally cash) for it. Generally you base what you can off that; see what they've done, extrapolate into the future based on it.
As for the random chance bit... yeah, more than a little, really. And campaign/get elected, well. Someone with money decides they either want a political position or want a friend (/person somewhat indebted to them) in a place of power, and then throws cash at advertising until they get enough name awareness people will vote for them. That's basically how it operates on any level besides the very, very small (and usually even then, the process is the same just on a smaller relative scale.).
Of course, that's if you're actually trying to be informed. Most folks, it's more or less like Aqi said
Though I'm not really sure what happens in situations where there's only one person running, other than victory by default barring write-ins or something. Doesn't happen very often where I'm at, at least since I've able to vote.