Skip to content

Instantly share code, notes, and snippets.

@titusfortner
Created October 20, 2014 17:29
Show Gist options
  • Save titusfortner/f0f0e43834a678926201 to your computer and use it in GitHub Desktop.
Save titusfortner/f0f0e43834a678926201 to your computer and use it in GitHub Desktop.
Rescue NoSuchWindow
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