Sometimes F150 starts, sometimes it doesn't

We have a 1999 f-150 just turned 200,000 miles. Two years ago replaced battery and alternator. Problem now sometimes starts fine, other times nothing. Can’t jump it. Took battery out and had it tested and it is fine. Cleaned connectors. May start after thirty minutes, an hour, a day. Then runs fine for a few weeks or months, then problem returns. Have taken to two shops, but mechanics said couldn’t find anything wrong bc of course it started fine at their shops! When wont start, Lights are on, but when try to crank, they go out and you hear nothing. Thoughts?

"when try to crank, they go out"
That means there is a large voltage drop (ie, large resistance) somewhere between the battery and the starter. Given that the dash lights go out, that means it is in the wiring common to the starter and the rest of the car.

To me that means the cables directly connected to the battery. That includes the ground connection. Some time with a voltmeter should pinpoint this problem. It could be a corroded connection or inside a cable. When you cleaned the connectors, did you clean all of them, 4 or 6? unbolt them and clean inside, at the actual contact area?

I agree with BillRussell since I just fixed my HHR that had this same exact problem last weekend. It turned out to be a bad ground cable connection.

Thanks yall. When you asked if there were four or six, I am a little confused. Do you mean two being the posts on the battery and two being the cable connectors? If so, there are four. wondering if the battery cables need to be replaced as I think we have never done that and these could be the originals.