By Michael Wursthorn and Joe Wallace

U.S. stocks struggled to find direction Friday, putting the S&P 500 on course to notch meager gains for the week while hovering just below its February record.

The broad index was recently up less than 0.1%, the latest in a series of modest moves that have left major indexes little changed from where they were a week earlier.

The S&P 500 attempted several runs this week at a new high, which would have marked its fastest recovery from a bear market ever and erased the losses suffered during the coronavirus pandemic. But the index repeatedly fell short, leaving it up just 0.7% from last Friday.

The market's trepidation reflects the uncertainty facing investors and the country as coronavirus cases and deaths continue to rise, analysts said. The main sticking point that dogged markets lately is the continuing haggling between lawmakers over additional aid to help the unemployed that failed to gain traction.

Fresh economic data, including unemployment claims and retail spending, continue to suggest the economy is recovering, albeit slowly. Whether the recovery can persist in the absence of further stimulus is something investors are weighing now, analysts added.

Despite those concerns, stocks are trading near their highest levels ever, stretching valuations to a point that hadn't been seen since the dot-com bubble. Tech stocks, which have driven much of the stock market's recovery, are even pricier and have traded sideways all week.

"There's a lot of confusion out there," said Larry Swedroe, chief research officer at Buckingham Wealth Partners, of his conversations with investors in recent weeks. "They ask how could stock prices be so high when we're going through this terrible crisis."

Not helping matters is the looming November election, which is less than three months away. Former Vice President Joe Biden named his running mate, Sen. Kamala Harris, on Tuesday, clarifying the Democratic presidential ticket. Several investors said they expect to see some election-induced volatility as November nears, particularly if Democrats appear likely to fare well. The would raise the likelihood of higher corporate taxes and regulation in 2021.

"The risk of a Biden win could have big, negative implications for the market," said Mr. Swedroe, although he added trade tensions between the U.S. and China would likely improve in that scenario.

On Friday, the Dow Jones Industrial Average picked up some traction in afternoon trading, rising 54 points, or 0.2%, to 27951.32. The Nasdaq Composite remained in the red, down 0.2%, as Apple, Facebook and Amazon.com all notched small losses.

Industrial and energy stocks notched the biggest gains of the day, rising 0.8% and 0.6%, respectively. But without the participation of tech stocks, which make up a significant chunk of the market's influence, the S&P 500 continued to the hug the flatline throughout most of Friday's session.

"The market has been quite stoical this week," said Jane Foley, head of foreign-exchange strategy at Rabobank. "It's August, so we may have to wait until September to find any strong direction."

Money managers are also awaiting trade talks between senior U.S. and Chinese officials, scheduled for Saturday. Relations have deteriorated in recent months, concerning investors who think fresh barriers to trade would further hurt the global economy.

The main thrust of the discussion is aimed at evaluating China's compliance with a bilateral trade agreement signed in January. Chinese Vice Premier Liu He, President Xi Jinping's chief trade negotiator with Washington, is expected to bring up concerns over the executive orders against the WeChat and TikTok apps.

"The tone of these talks will be crucial," Ms. Foley said. "There is a concern that China has perhaps not fulfilled its promises in, for example, importing agricultural or energy goods from the U.S."

Several retailers are also expected to report quarterly earnings next week, giving investors additional windows into consumer activity. Walmart, Home Depot and Kohl's are due to disclose results on Tuesday, while TJX and L Brands follow later in the week.

In overseas markets, travel-and-leisure companies led European shares lower, pushing the Stoxx Europe 600 down 1.2%. The U.K. government late Thursday imposed a quarantine on people traveling from France, the latest in a series of restrictions designed to stem rising coronavirus cases in the region.

The Shanghai Composite Index rose 1.2% after data showing China's recovery continued in July, though the economy shed some momentum as Beijing eased off stimulus measures.

Write to Michael Wursthorn at Michael.Wursthorn@wsj.com and Joe Wallace at Joe.Wallace@wsj.com