Nutation or Circumnutaion is the term used to describe how plant stems bend and move, it allows tendrils of plants to locate and grab hold of supports. The first comprehensive study of this process was done by Charles Darwin in 1865 in his work "On the Movements and Habits of Climbing Plants". The term Circumnutation was coined by Darwin in this study.
Clearly the plant doesn't know where the support is, but by successively growing the stem at different rates on either side it is able to move in a spiral pattern. Eventually the tendril will touch something, at which point the spiralling motion - rather than causing the stem to flail around randomly - will cause it to wrap around the thing it touched.
Its a fascinating process, there is no plan, no concious thought or knowledge of the surrounding area, it just happens all by itself. The simple act of irregular growth of a stem provides a surprisingly reliable mechanism for the plant to feel its way around and support itself, allowing plants such as peas, cucumbers, and other climbing plants to grow heavy fruit which would otherwise collapse it.
I've been growing some plants on my windowsill and was able to observe and record this process in a cucumber plant. It happened surprising quickly - the footage represents about 4 hours growth sped up to about 5 minutes.