Refactored the logic to get the form field

This extracts some logic to reduce the complexity of the method. There is also a few benefits:

- computing the position is now done only when it is actually needed (most fields will probably not need it), thus avoiding an xpath query in most cases
- the logic to find the form element for a field can now be reused for other elements, as needed in #41