1
votes

Okay, so I have a script that is supposed to open a pop-up window and do a few operations on that window. I'm running into some trouble where the window opens, but the script stalls until I manually click the window, then it finds it and I can proceed.

I'm using the latest Watir-Webdriver and ChromeDriver (because it executes by far faster than IE or Firefox)

#problem area of the script
#use send keys due to modal window
b.frame(name: 'MainBody').link(text: 'Add Event').send_keys :return
b.window(title: 'Add Event').use do
  #do some stuff
end
b.window(title: 'Add Event').wait_while_present

After the button is clicked, the window opens, and nothing happens. One I manually click the window, the script wakes back up and moves on.

I tried just putting a puts statement right after the send_keys, but it doesn't get executed until after I click the window, and those don't work either until the window is manually clicked. I also tried a monkey patched click_no_wait method to rescue.

Any ideas?

2

2 Answers

3
votes

A dirty method would be:

 b.windows.last.use        #to switch to the new tab/pop-up window
        b.window(title: 'Add Event').use do
            #do some stuff
        end
    b.windows.last.close    #to close the new tab/pop-up window
    b.windows.first.use     #to return to initial tab/pop-up window

Worked 100% of the time for me.

0
votes

Maybe it's trying to go too fast? you could try something like

b.window(title: 'Add Event').when_present.use do #do some stuff end