Volvo 1998 S70 four door Sedan automatic

The problem Ive been having with my car is that gear lever doesn’t release. When I press on the break, it doesn’t immediately release. It is an intermittent problem. Upon the recommendation of factory trained technicians, I replaced the switch on the break on the foot pedal. Unfortunately, there was no change. The next recommendation from the factory trained technician was to replace the locking solenoid. Is there any way I can pinpoint the problem without replacing the entire system?

“Mechanic?!”? You can use a multimeter and measure across the switches involved for voltage drops, and you can measure resistances throughout the affected circuits.
When taking these circuit measurements, actuate the switch(es) several times (taking measurements each time). If there is a different value(s) the switch (or, other component) is problematic.