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
Hey,
ReplyDeleteVery useful info. THanks. More selenium 2 article please :)
Thanks, its very useful!
ReplyDeleteHello, I am trying to use your implementation above and am having no luck. I am using selenium and cucumber to run my automation tests (I am new only 6 months exp) and need to create the step definitions. My application opens, enters some data and clicks "complete" then a new windows opens and I get any errors/warnings. I need to click that button, switch, validate messages and come back to the main window. I cannot get my step definition to work and keep getting undefined method 'window_handles'. Any chance you know how to get this into a step definition?
ReplyDeleteThanks
Hi MonsterEnergy,
Deleteyou should probably use 'page' instead of 'response' everywhere, like this:
page.driver.browser.switch_to.window(page.driver.browser.window_handles[0])