When I was praying for the election of Ratzinger as Pope, I recalled Acts
..a witness with us of his resurrection. 23 And they appointed two, Joseph, called Barsabas, who was surnamed Justus, and Matthias. 24 And praying, they said: Thou, Lord, who knowest the hearts of all men, shew whether of these two thou hast chosen,
*The Cardinals gathered in the Sistine Chapel, similarly, pray for guidance from the Holy Spirit in choosing a successor to the deceased Pope
And the Holy Spirt always answers. If we get a bad Pope (very, very, rare) it serves to remind us who it really is who is the ultimate Head of the Church that can't fail. If we get Holy and Theologically Brilliant Popes (such as Johannes Paulus Mangus and Pope B.) we get the opportunity for great joy and pride