-
-
Save jarib/1206426 to your computer and use it in GitHub Desktop.
modal dialog issue
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
require 'rubygems' | |
require 'selenium-webdriver' | |
require 'pp' | |
dir = Dir.mktmpdir("modal-dialog") | |
htmls = DATA.read.scan(/--- (.+?) ---\n(.+?)(?=---|\z)/m) | |
htmls.each do |name, content| | |
File.open(File.join(dir, name), "w") { |io| io << content} | |
end | |
wait = Selenium::WebDriver::Wait.new | |
browser = Selenium::WebDriver.for :ie | |
browser.navigate.to "file://#{dir}/modal.html" | |
original_handles = browser.window_handles | |
browser.find_element(:id, 'launch_modal_button').click | |
handles = nil | |
wait.until { | |
handles = browser.window_handles | |
handles.size == 2 | |
} | |
modal = (handles - original_handles).first | |
pp :handles => handles, :original_handles => original_handles, :modal => modal | |
browser.switch_to.window(modal) | |
browser.find_element(:id, 'close_window').click | |
__END__ | |
--- modal.html --- | |
<html> | |
<head> | |
<title>modal dialog test page</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
function modal() { | |
var retValue = window.showModalDialog( | |
"modal_1.html", self, | |
"status:no;resizable:Yes;help:no;maximize:no;minimize:no;scrollbars:no;"); | |
} | |
</script> | |
<input id=launch_modal_button type=button onclick='return modal();' value="Launch a modal" /> | |
</body> | |
</html> | |
--- modal_1.html --- | |
<html> | |
<head> | |
<title>Modal 1</title> | |
<script> | |
function delay_action(other_function) { | |
setTimeout(other_function, 3000); | |
} | |
function close_window() { | |
window.returnValue = 22 | |
window.close() | |
} | |
function modal1() { | |
var retValue = window.showModalDialog( | |
"modal_2.html", self, | |
"status:no;resizable:Yes;help:no;maximize:no;minimize:no;scrollbars:no;"); | |
} | |
</script> | |
</head> | |
<body> | |
<h2>Modal 1</h2> | |
<h3>Close buttons</h3> | |
<input id=close_window type=button onclick="close_window()" value="Close window"/> | |
<input id=delayed_close type=button onclick="delay_action('close_window()')" value="Close window with delay" /> | |
<h3>Nested modal</h3> | |
<input id=launch_modal_button type=button onclick='return modal1();' value="Launch another modal"/> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment