Anna Downs, 24, had been heading home from visiting a friend in Gilmerton when she stopped at traffic lights on the bridge on the B704 road near Dalhousie Castle, Midlothian.
The mother-of-two said she “froze” when she saw a “shadow” appear beside her car and try to open the door on the driver’s side.
When she saw the man go round the car to try the passenger door, she sped away from the scene, thankful that she had locked her doors.
After arriving home, she remained so traumatised that she had to call a friend to come to her house in Gorebridge as she was scared to leave her car.
Ms Downs, a barmaid, said of Thursday’s early morning ordeal: “He tried the door about four or five times and realised that he couldn’t get in. He went round the front of the car to try and go to the passenger side.
“At that point I drove off. I just froze the moment he got to the driver’s side. I didn’t really know what to do.
“I was just in shock and then I started to panic. It was at about 2am, it was pitch black. It’s a wooded area down there, it’s the middle of nowhere.”
Ms Downs posted her ordeal on social media to spread the word, and her post has now been shared more than 1500 times.
She said she would steer clear of that stretch of the B704 and was relieved her children, aged six and two, hadn’t been with her at the time.
“I just want people to know what happened,” she said. “I didn’t want it to happen again with people not knowing. Just be vigilant and lock all the doors. Even when you’re inside the car, lock your doors. I always do that. I lock my doors before I put my seatbelt on.
“I don’t know what the guy’s intentions were, but I’m so glad that I do lock my car door.”
Several people have been in touch with Ms Downs since she posted the online message, to say they have reported other suspected criminal behaviour in the nearby area.
Among these were reports that two men were spotted trying to break into the car in a nearby area.
Another person said they saw a “creepy-looking” man with a hood up just past the lights, towards Gorebridge.
The man who approached Ms Downs’ car is described as white, in his 30s, with heavy stubble.
Ms Downs said: “I didn’t want to look at him, I shut my eyes and thought, ‘I don’t want to see this person’. But I got a profile of him as he went round the car. He did have his hood up. He was unshaven and unkempt.”
She said he was wearing a dark waterproof-style jacket, which was slightly “shiny” in her car headlights, and white trainers.
Inspector John Dryden said: “We were quickly alerted to this incident by the driver and officers carried out searches of the surrounding area but the man was not located.
“We do not know why he was attempting to gain entry to the car and are keen to speak to anyone who may have seen him in the vicinity beforehand or afterwards.”
Contact Police Scotland on 101 or Crimestoppers anonymously on 0800 555 111.