Well I'd try everything else before hand. I'd try to pry the door open, try to call someone, try to fiddle with buttons, and try to climb out of the top. But if none of those things worked, whether I'm alone or not, I'd pee in the corner.
Well being stuck in an elevators the worst tbh from now on im carrying a bottle around with me just in case. :P
btw: theres a shopping centre called the glades in england where theres two glass elevators that the whole shopping centre usually filled with hundreds and hundreds of people can see, if i was stuck there and needed toilet i would just ...... :(
Where I live pissing in elevators is a daily occurrence and you don't need to be stuck in there for it to happen. Inside the elevator there are carvings such as "f... this place" and "take a shower" etc... its funny because the people who do that are the ones who are pissing and throwing their babies diapers in the trash near the lobby door. I feel sorry for the rent lady who has to show people a place this building is the worst out of the entire complex.
Anyway if I were stuck in an elevator the last thing I would be worried about is where to go to the bathroom. Who knows how long I would be in there for... but I like to think ahead and I don't want to be rolling in waste if I had to sleep.