I am assuming your batteries tested ok. To me, it sounds like it could be the starter solenoid, right behind the battery compartment. When you turn the key for the starter, the small wire energizes the solenoid. The solenoid can be intermittent, not working sometimes and works other times. You have voltage coming into the solenoid, then when you turn the starter switch on, it energizes and goes to the starter. If you have problem starting, have someone is back there, your can hear and feel it clicking. You can check the small stud and see if you are getting voltage to it. If it is not working you can also bypass it by touching a wire between the two large studs. You do have make sure the key is in the run position. It is not expensive and easy to replace. If it were me, I would just replace the solenoid.
If that is working fine, It could be your starter solenoid (mounted to top of the starter). They can be intermittent too.
2007 Apex MDTS (425 hp) #75723
2007 Toyota 4-Runner
2014 Ram Laramie 3500