Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

WASHINGTON — Democrats have been here before. They're ahead in the polls, the Republican Party is divided and President Donald Trump's flaws have been dominating the political landscape.

And we all saw how that turned out for the party in 2016.

So as Virginia voters choose their next governor on Tuesday — either Democrat Ralph Northam or Republican Ed Gillespie — the central question has become: Unlike in 2016, can Democrats finally win with those advantages? Or will Republicans once again pull off the upset?

Those are the stakes, especially a year away from the all-important midterm elections in 2018, when control of the U.S. House is up for grabs and when Trump's presence is sure to play another outsize role.

"The big storyline is whether the Democrats can begin to capitalize politically on an environment that looks very bad for Republicans given the president's high unpopularity in the state," said Mark Rozell, dean of the Schar School of Policy and Government at George Mason University.

Referring to Tuesday's gubernatorial races in Virginia and New Jersey, Jennifer Duffy of the Cook Political Report said Democrats "are hoping to turn two victories into momentum."

The Trump factor

With the White House just miles away from Northern Virginia, Trump's presence has hovered over the race — for both candidates.

After calling Trump a "narcissistic maniac" during the Democratic primary, Northam has continued to tie the president — whose approval rating stands at 38 percent in the state, according to a recent Washington Post poll — to Gillespie.

"Ed Gillespie supports Donald Trump's plan to take money out of Virginia's public schools, his plan to roll back our clean water and clean air protections, and Ed Gillespie supports Donald Trump's plan to take health care away from thousands of Virginians," one of Northam's most recent TV ads goes.

"Ed Gillespie won't stand up to Donald Trump because Ed's standing right next to him," the ad concludes.

Gillespie, meanwhile, has borrowed heavily from the Trump playbook — on the issues of immigration and crime — especially after narrowly beating a pro-Trump primary candidate.

"Ralph Northam cast the deciding vote in favor of sanctuary cities that let illegal immigrants who commit crimes back on the street — increasing the threat of gangs like MS-13," an Gillespie ad said. (There are no sanctuary cities in Virginia.)

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

"Ralph Northam wants to take down Virginia's Civil War monuments," goes another Gillespie ad. "I'm for keeping them up, and he's for taking them down." Gillespie says to the camera.

Northam enjoys almost every structural advantage

Most polls have shown Northam ahead in the race, and there's an easy explanation: He enjoys almost every structural advantage.

Trump: In addition to his 38 percent approval rating in The Washington Post's poll, 57 percent of voters say their views of Trump are important in deciding their votes.

History: With just one exception (in 2013, when Terry McAuliffe defeated Ken Cuccinelli), the party that controls the White House has lost every gubernatorial election in Virginia going back to the 1970s.

The GOP's poor performance in Virginia: Since 2005, Democrats are 9-1 in major statewide elections in Virginia (for president, Senate, governor), including Hillary Clinton's 5-point victory in 2016.

Cash: Northam is outraising Gillespie, which is striking given Gillespie's background as a former chairman of the Republican National Committee and lobbyist.

The advertising war: Northam is outspending Gillespie on the TV airwaves, while party spending has been about even.

"If Democrats lose, it will be a very big story, and there will be many assessments of what it means about the party's prospects in the midterms next year," Rozell said.

Can Gillespie escape from Trump's shadow?

But Gillespie has two potential advantages that could explain how he could pull off the upset on Tuesday.

The first is turnout. Going back to 2006, exit polls show that Democrats have enjoyed, on average, a nearly 7-point advantage in party identification (between Democrats and Republicans) in presidential years, while party ID has been close to even in non-presidential elections.

So for Gillespie to win, he needs the electorate to look like it did in 2014, when he narrowly lost Virginia's U.S. Senate race to Democrat Mark Warner.

Gillespie's second potential advantage is his biography — former RNC chairman, counselor to former President George W. Bush, high-ranking official in Mitt Romney's 2012 campaign — which might allow him to thread the needle of winning over moderate Republicans and independents in urban Northern Virginia but also carrying Trump voters in rural parts of the state.

But threading that needle isn't easy.

"If there's anyone who can figure out how to run with Trump, it will be Gillespie," said Duffy of the nonpartisan Cook Political Report.

"I think Democrats are understandably nervous because of 2016"

Gillespie's allies think he has the momentum, especially given the furor over a pro-Northam ad suggesting that Gillespie voters had Confederate flags on their trucks and were hunting down minorities.

"Republican voters are dialed in and fired up," one Gillespie adviser said.

But Democrats remain confident that Northam has the advantage going into Election Day.

"The race is tight, but I'd rather be us than them. And I don't think that's changed dramatically over the last few months," said Jesse Ferguson, a Democratic strategist who's been involved in past Virginia races.

Yet Northam's campaign knows that Democrats remember what happened in 2016.

"I think Democrats are understandably nervous because of 2016," said David Turner, Northam's communications director, who said the campaign feels "pretty good" heading into Election Day. "Nobody thinks anything is in the bag anymore."

CORRECTION (Nov. 6, 2017, 9:27 a.m.): An earlier version of this article included an incorrect quotation from Mark Rozell of George Mason University. He referred to Trump's high unpopularity in Virginia, not his popularity.