Created
October 20, 2014 17:29
-
-
Save titusfortner/f0f0e43834a678926201 to your computer and use it in GitHub Desktop.
Rescue NoSuchWindow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def window(id) | |
if block_given? | |
begin | |
original = @bridge.getCurrentWindowHandle | |
rescue Selenium::WebDriver::Error::NoSuchWindowError | |
original = nil | |
end | |
@bridge.switchToWindow id | |
begin | |
returned = yield | |
ensure | |
current_handles = @bridge.getWindowHandles | |
if current_handles.size == 1 | |
original = current_handles.shift | |
end | |
@bridge.switchToWindow original unless original.nil? | |
returned | |
end | |
else | |
@bridge.switchToWindow id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment