You cant check if a widget object is visible unless you null check first.
I would try getwidgets#isvisible(int int) just to check if it exists and visible.
For the repeating actions, take a look and redo tour script logic.
Look into conditionsleep also.