The S&P 500 and the Nasdaq composite indexes closed at record levels on Friday as investors looked ahead to a key European election.

Both indexes, along with the Dow Jones industrial average, rose sharply heading into the close after hovering around the flatline for most of the session. Shares of Apple closed at a record high, helping lift the Dow and Nasdaq.

The Dow, S&P and Nasdaq also posted slight weekly gains and traded in a narrow range for most of the week.

"This narrow trading range tells us a few things," said Art Hogan, chief market strategist at Wunderlich Securities. "First, we went up 2 percent the week before. Second, we're near all-time highs and finally, earnings season is over and we now shift our attention to macro issues."

Major indexes this week

Source: FactSet

French citizens will elect a new president on Sunday. Centrist Emmanuel Macron is widely expected to defeat far-right candidate Marine Le Pen. Macron, contrary to Le Pen, is a staunch supporter of keeping France in the European Union.

The euro surged against the dollar following the first round of the election and has hovered around $1.099 since.

"I think there will be a reaction to the upside if Macron wins, but it won't be as significant," said Peter NG, senior FX trader at Silicon Valley Bank.

U.S. equities traded in a narrow range for most of Friday after the Labor Department reported solid jobs growth for April.

The U.S. economy added 211,000 jobs in April and the unemployment rate fell to 4.4 percent. Economists polled by Reuters expected jobs growth of 185,000 and for the unemployment rate to hit 4.5 percent.

"The market reaction was a little muted. I think there's just caution out there," said JJ Kinahan, chief market strategist at TD Ameritrade. "People are saying there's no caution as seen on the Vix, but where you are seeing caution is in people not going out and buying everything at these levels."

Average hourly wages, meanwhile, rose 0.3 percent.