Correct the code in WidgetUtils to be more robustic when elements are dynamic.