Skip to content

Instantly share code, notes, and snippets.

@titusfortner
Last active August 29, 2015 14:10
Show Gist options
  • Save titusfortner/a5a6c6dae66bc0cbd3b3 to your computer and use it in GitHub Desktop.
Save titusfortner/a5a6c6dae66bc0cbd3b3 to your computer and use it in GitHub Desktop.
ChromeDriver Issue #950
require 'selenium-webdriver'
first_window = File.open('window1.html', 'w').tap {|f| f.puts "<html><head><title><Window1</title></head><body><p>Click <a id='open' href='#' onclick='window.open(\"window2.html\")'>here</a></body></html>" }
first_window.close
File.open('window2.html', 'w').tap {|f| f.puts "<html><head><title>window1</title></head><body><p>Click <a id='close' href='#' onclick=\"window.close()\">close</a></p></body></html>" }.close
driver = Selenium::WebDriver.for :chrome
driver.navigate.to "file://#{File.expand_path(File.dirname(__FILE__))}/#{first_window.path}"
driver.first(id: 'open').click
driver.switch_to.window(driver.window_handles.last)
driver.first(id: 'close').click
#driver.window_handles ### If you un-comment out this line, the test will pass
begin
driver.window_handle
raise "This test did not throw the expected NoSuchWindowError"
rescue Selenium::WebDriver::Error::NoSuchWindowError
puts "This test passes as expected!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment