'Al', in the example you give: 'Al encontrar', 'al' is used as
'upon', as in 'Upon finding the car keys, I'll go to the library' =
'Al encontrar los llaves, voy a la bibiliteca'. In English, in some
cases, we CAN say 'when' instead, as in 'When I find the car keys,
I'll go to the library'. It is much easier to think about "upon", even
though in everyday speech, we don't use 'upon' much in English. I find
it much easier to remember 'upon' as it's meaning.
'Al' is used with an infinitive, as you already surmised.
Al llegar a mi casa, voy a dormir = Upon arriving home, I'll go to
sleep. When I get home, I'll go to sleep.
Al alcanzar su meta, se retiró. = Upon reaching his goal, he retired.
When he reached his goal, he retired. After he reached his goal, he
Al montar el avion, tome un asiento. = Upon boarding the plane, I took a seat.
Llegamos tarde al encontrar el autopista cerrada. = We arrived late
upon finding the freeway closed.
Cierre la ventana al terminar= Close the window upon finishing/when you are done.
Ella no quiso el pastel al saber que es de fresa. = She did not want
the cake upon learning it has strawberries. (Note, 'pastel' means
'cake' in some countries, and 'pie' in others.
Marta se desmayó al ver el cadáver de su hermano. = Marta fainted upon
seeing her brother's dead body.
Using 'al' makes the sound of the sentence flow easier. I find it
rolls off the tongue nicely! 'Al montar el avion' is smoother than
'Despues que me monto el avion'...
A + el also = al When referring to a masculine noun, a=to el=the = al
As in 'Daselo al jefe' = Give it to the boss.
'Llevalo al carro' = Take it to the car
These pages may help you, as a beginner:
Al leer ésta respuesta, favor de pedir una Answer Clarification, si
hay algo que no entiende. = Upon reading this answer, please ask for
an Answer Clarification, if there is anything you don't understand!
Le saluda atentamente, Crabcakes
PS. Online translators are still very imprecise, and can't be counted
on for accuracy! They can assist you in getting an "idea", but most of
what I have seen do a very poor job! Use caution!