Back before the seventeenth amendment was passed, Senators were not directly elected. They were chosen by the state legislatures. But how exactly did that work? Most states have a bicameral legislature - did one house or the other choose the senator or did they vote as a combined group? Did the rules vary from state to state?
Check the Wikipedia article. It seems pretty clear that different states handled it differently.
Whichever method the state chose, it was likely not very fair and prone to a lot of partisanship and backroom dealings.
Also since state legislatures used to meet for fairly short terms that didn’t match up with the Federal election cycle, sometimes the choices would be done very early.
In 1868, the President Pro Tem of the Senate, Benjamin (Bluff Ben) Wade of Ohio wasn’t even nominated by the Republicans for another term. Yet he was poised to take over the presidency if Andrew Johnson had been impeached.
James Garfield was picked as Ohio’s senator for the Congress that would start in 1881 in January of 1880. He was still a member of the House when he ended up being elected president instead.
In 1881, Roscoe Conkling and Thomas Platt of New York both resigned their Senate seats in protest over patronage snubs by Garfield and hoped to get reappointed by the New York legislature.
Except they didn’t get chosen again. Platt would eventually rejoin the Senate in 1897.
Prior to 1866, each state was allowed to write its own rules, so procedures varied by state. In most states, the two houses would meet in joint session and ballot as a unit. In a few states, such as Massachusetts, the houses would ballot separately, and you needed a majority of each house to win.
In 1866, Congress took advantage of its power to regulate the “manner” of Senate elections by passing a federal law to impose uniform rules on all the states. I can’t find the text of this law online, but it required that elections begin with a single separate ballot of each house. If a candidate won a majority of each house, he won the seat; if not, then the houses would ballot together until somebody won a majority of the joint membership. The law also specified when balloting could begin and how many ballots had to be conducted each day.