follow me icons

Wednesday, October 6, 2010

Testing Pop up windows using Selenium webdriver

There are times when we need to test a pop up windows within the current browser. For example of this is when you try to test a pop up box for the user to fill in the user details or a print pop up box.

The problem is that the webdriver will still focus on the current browser and not the pop up windows and therefore any interaction will only go to the browser and not to the new pop up browsers.

To solve this simply switch the browser to point to the pop up.

Here is the implementation for selenium webdriver in ruby

def switch_to_new_pop_up
response.driver.browser.switch_to.window
(response.driver.browser.window_handles.last)
end

def close_active_window
response.driver.browser.close
response.driver.browser.switch_to.window
(response.driver.browser.window_handles[0])
end

1 comment:

  1. Hey,

    Very useful info. THanks. More selenium 2 article please :)

    ReplyDelete