Modal Web Dialogs (Show Modal Dialogs)
Background Information
These are only supported by Internet explorer, so tend not to appear all that often. They contain html, but need to be accessed in a certain way.
The following html code would open google in a modal dialog.
window.showModalDialog('www.google.com')
The following dialog was created using the script on http://msdn2.microsoft.com/en-us/library/ms536759.aspx
Note the title of the window - Web Page Dialog - this is a way of determining if you are dealing with a modal dialog or a regular browser window. With a modal dialog, you wont be able to give focus to your main browser window.

Using Watir to Control Modal Web Dialogs
There is a specific method to handle modal dialogs, called modal_dialog. An example script is below:
require "rubygems" require "watir" b = Watir::Browser.new() b.goto("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog2.htm") b.button(:value,"Push To Create").click_no_wait puts b.modal_dialog(:title, "showModalDialog Method Sample Target Page").exists? puts b.modal_dialog(:title, "showModalDialog Method Sample Target Page").title b.modal_dialog(:title, "showModalDialog Method Sample Target Page").close
Also, if using Internet Explorer 8, you will need to make changes to the modal_dialog.rb file in your gems directory, see: http://jira.openqa.org/browse/WTR-414.
Comments (5)
Feb 10, 2010
Raveendran says:
Hi, If the Modal Dialog window has some code looks like CODE Side: <html...Hi,
If the Modal Dialog window has some code looks like
CODE Side:
<html><head>
<script> SOME ACTIONS </script>
</head></html>
View Side :
It has lot of tree related links(Not pure a href link. Also i couldn't able to view the source for that texts and links)
My Question is
1. Can I able to access the links within the Modal dialog box ?
If yes, then please guide me
If no, Please add this point in wiki and mention the details
Awaiting your reply,
Thanks
Jun 03, 2010
Oleg Neiman says:
Hi Raveendran, did you get any feedback to your question?Hi Raveendran,
did you get any feedback to your question?
Oct 15, 2010
Raveendran says:
Hi Oleg. No.. I understood Watir doesn't support to handle that particular wind...Hi Oleg.
No.. I understood Watir doesn't support to handle that particular window.
Thanks
Jan 17
Sabarish says:
Hi, I am getting below error when I am trying to execute above code, I am using...Hi,
I am getting below error when I am trying to execute above code, I am using IE8, so I have taken taken modal_window.rb from above link. Can some one help me to resolve this?
undefined method `modal_dialog' for #<Watir::IE:0xef1078> (NoMethodError)
Thanks
Jan 24
Zeljko says:
We do not provide Watir support here. See this page on how to get support: http:...We do not provide Watir support here. See this page on how to get support: http://watir.com/support/