This is going to massively depend on which country you live in, but frequently neither.
Parties can pick who they like, but they often allow politicians and party members to vote as part of internal selection process.
In the UK only weirdos and political extremists are party members, and the Tory party tends to spend a lot of effort trying to stop their members from having a vote.
So of the last four prime ministers.
Sunak didn't have a vote (lost to truss before that).
Truss won an internal vote.
Johnson won an internal vote.
May was uncontested.
And this is only the internal vote. All of them became prime minister without an election. Generally you vote for a party (some pedant will claim you vote for MPs, but they do what the party says) and then the leader can change while they're in power.