When I was younger (not that long ago, almost 21 now), we always visit the cockpit. One time on a HKG-SFO my brother and I both got to sit on the pilot's seat as well. This usually happens in the beginning of the boarding process. We usually ask a FA who would then ask the cockpit crew.