Here's what Josef Cardinal Ratzinger, Pope Emeritus Benedict XVI, replied in 1997 when he was asked by a reporter on Bavarian TV whether the Holy Spirit picks the pope:
I would not say so, in the sense that the Holy Spirit picks out the Pope.... I would say that the Spirit does not exactly take control of the affair, but rather like a good educator, as it were, leaves us much space, much freedom, without entirely abandoning us. Thus the Spirit's role should be understood in a much more elastic sense, not that he dictates the candidate for whom one must vote. Probably the only assurance he offers is that the thing cannot be totally ruined.....There are too many contrary instances of popes the Holy Spirit obviously would not have picked. SourceObviously we are called to honor our spiritual father on earth, but don't mistake him for someone he is not. The pope is not God and every pronouncement he makes is not necessarily from the mouth of God. We have had many bad popes who were more diligent about advancing their own interests than the will of God. How do we know a good pope from a bad one? Jesus told us, "by their fruits." How will you know if their fruits are good? Do they advance the faith consistent with the unchangeable doctrine of Holy Mother Church? How will we know if their actions are consistent with the doctrine? STUDY THE FAITH. KNOW THE DOCTRINE!
If you don't know the faith, you are susceptible to every shifting tide and every variable wind. You can only be rock solid if you are firmly attached to the rock of the faith which the Holy Spirit promises cannot be destroyed. And that is the meaning of "Where Peter is, there is the Church." It doesn't mean that Peter is holy or that everything he says is the truth, but only when his words and actions match the unchanging doctrine of Holy Mother Church. Love God, pray unceasingly, and discern the spirits.