edit test script
re-work the implementation with looping so that it now correctly works for a window