Pilots take turns to visit the lavatory.
When one of the pilots needs to use the facilities, a flight attendant goes into the cockpit and waits until the pilot returns. This is done to avoid issues such as being locked out of the cockpit while the second pilot suddenly passes out.