Didn't both parties claim to represent the impoverished German masses against the decadent bourgeois elite?
Well it's obviously incredibly difficult, if not outright impossible, to exactly answer such a question. I can approach it at least with some analysis.
First and foremost my primary source on this is "Anatomy of Fascism" by Robert Paxton coupled with a variety of general histories on WWII and Germany during this period.
Firstly, I would not necessarily describe the situation as "Germans siding with the Nazis instead of the Communists" There were a great many Germans who were opposed, actively or passively, to the Nazi party and their rule (many of them Communists or Socialists). Moreover, the Nazi's never won a governing majority in a free and fair election. The best electoral performance by the Nazis was in the early 1932 election in which they won 37% of the vote and 230 seats. While the largest party, they were still over 70 seats away from a majority. In the last free and fair election in late 1932 they actually lost about 30 seats while the Communists gained a few. Ultimately the Nazi party seized power, rather than being elected to power. President Hindenburg (himself a staunch conservative) believed that a coalition government between the Nazis and the more traditional conservatives was preferable to further emergency presidential rule, another election, or a leftist coalition (which would itself have been very uneasy, more on that later). The rest is, as they say, history. The Reichstag fire gave the perfect pretense to give the Nazis emergency powers and they subsequently used those powers to crush both external and internal opposition. Consolidating Germany into a one-party dictatorship. I say all this to note that, at no point, did the Nazis have a majority electoral support from German people.
Secondly: The Nazis absolutely did present themselves as an alternative to "Jewish-Bolshevism" as they called it, and did at various times claim to represent the oppressed (aryan) working class. But one of the defining traits of Fascism, according to Paxton, is its ideological incontinuity. Simply put: the Nazi's wanted to appeal to as many people as possible by being ambiguous and inconsistent, appearing to be whatever you wanted them to be. At one time presenting themselves as a socialist party for the working class, but also as a vehemently conservative party. As a party for working class (aryan) Germans, but also good for business and able to get funding from the major heads of German industry. From a socialist perspective these things seemed contradictory: and that's because they were. Ideological consistency was never really the Nazi's strong suit. But that is an even larger topic for another time.
Lastly: why didn't people side with the Communists/Socialists? This is a very interesting one that really does rely quite a bit on context. Firstly the leftist movement in Weimar Germany was incredibly divided (if you do any amount of reading on leftist history, you'd know that this is basically always a given). The Communist Party of Germany originated as a split-off from the SPD (Social Democrats) who attempted a revolution in 1918 that was unsuccessful. The SPD was the cornerstone party of German politics in the early 20th century and frequently received the most votes. While nominally socialist, there were significant chunks of the party that were fairly moderate. The KPD (Communists) originated as members of the SPD who believed that a Bolshevik style revolution would be necessary to propel Germany to socialism, while the remaining SPD believed that democratic reform was the way. The SPD worked with the Freikorps (right-wing militias) in putting down the Spartacist Uprising of 1919 which only furthered relations between the two parties. Relations were again strained when the SPD put down the Ruhr uprising and the Hamburg uprising, which further tainted their credibility with various leftists as they willing collaborated with right-wing militants to put down left-wing uprisings.
In essence: the SPD believed that the Communists were violent radicals and would-be dictators, while the KPD believed the SocDems were conservatives in Socialist clothing. This is why the original KPD Antifaschistische Aktion was against both the Nazi Party AND the Social Democrat Party. The SPD was pretty consistently the largest party of the Weimar era and as such had a hand in much of what the Weimar government did, for better or for worse. As the years wore on the SPD began to erode support. Forced time and again to form coallition governments with more conservative/centrist parties many SPD supporters became disillusioned with them. Some leftists disillusioned with the SPD's shortcomings switched to supporting the Communists. Others who were disillusioned may have found the communists too violent/distasteful and shifted to supporting other parties (including even the Nazis, who prior to the night of long-knives did have a large leftist element).
Why didn't everyone flip to the communists? Well it's difficult to actually say exactly why but broadly speaking we could say that the Communist party was associated very heavily with violent uprisings/attempts at revolution which did them no favors in terms of PR. They also had very documented ties to Moscow which again was not necessarily helpful for electoral success. Moreover they were very unwilling to cooperate with the only party that was even remotely close to them Ideologically (the SPD) which meant that realistically the only way they could govern was by winning an outright majority which they were far, far from being able to do (Their best performance in late 1932 saw them winning 100 seats in the Reichstag, almost 300 was needed for a majority).
This was all a very long-winded and detailed way of saying: The Nazis never had as widespread and popular of a support electorally as they claimed, and that the various leftist parties of Weimar Germany were intensely divided and feuding with each other which left them unable to coalesce against the Nazis. Moreover the traditional conservative elements of Germany considered the Nazis to either be preferable to socialist/communist rule or believed that their more radical elements could be contained with Conservative parties acting as moderators in a coalition government (spoiler alert: they were wrong).
I would check out "Anatomy of Fascism" by Robert Paxton which gives a pretty good overview of the Nazi party's ideology and how they were able to maneuver into power as well as "Weimar Germany: Promise and Tragedy" by Eric Weitz. I hope this helped a little bit, I can try to answer more if needed, but some of it might be beyond my capability.