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