The pilot (or captain as they're called) is able to use the bathroom without any issues. Some airlines even opt to have a special bathroom for the crew installed. For airline pilots it's easy, just leave the cockpit according to protocol, respond to the call of nature and make your way back.