How to wait for a window to exist without fixed wait time