Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Modal dialogs (aka popups) are supported internally by Vapir for both IE and Firefox.

WinClicker is gone from Vapir.

AutoIt exists (the only thing currently using it is IE#send_keys) but is not recommended and not supported.

The Modal Dialogs API is listed here (it will be in rdoc as soon as issues with creating an rdoc for Vapir are resolved).

The API is different from Watir’s API (to such extent as API exists in Watir for this).

#modal_dialog methods

Vapir::IE#modal_dialog(options={})
Vapir::Firefox#modal_dialog(options={})
Vapir::Firefox::ModalDialog#modal_dialog(options={})
Vapir::IE#modal_dialog!(options={})
Vapir::Firefox#modal_dialog!(options={})
Vapir::Firefox::ModalDialogDocument#modal_dialog!(options={})

The #modal_dialog methods return a Vapir::IE::ModalDialog or Vapir::Firefox::ModalDialog object, if a modal dialog exists on the window in question.

If a bang-method is used, then the method will error if no modal dialog exists on the window in question. If a non-bang-method is used, nil will be returned in that case.

Options that may be passed (but may be omitted and a sensible default will be used) are:

  • :timeout => (a number) – the number of seconds to wait for the modal dialog to come into existence.

ModalDialog class

These methods apply to a modal dialog, such as what is generated by a javascript alert(), confirm(), or prompt(). They do not apply to html documents contained within modal dialogs opened via javascript showModalDialog. See the method ModalDialog#document and the class ModalDialogDocument to handle these.

#exists?
Returns true if the modal dialog exists. Returns false if not.

#text
Returns the text displayed in the modal dialog.

#set_text_field(value)
Not yet implemented for Vapir-Firefox
Finds a text field on the modal dialog, and sets its value to the given value. It is presumed that there is only one text field (as is the case with javascript prompt(), to which this is targeted).

#click_button(button_text)
Finds a button on the modal dialog with text matching the given text. Clicks on it.

#close
Closes the modal dialog.

May error if the modal dialog is not able to be closed.

#document
Returns a ModalDialogDocument (see its documentation below).

ModalDialogDocument

This represents an html document opened by a javascript showModalDialog. All of the container methods to access elements apply to this – it includes Vapir::PageContainer and Vapir::Container, which are documented elsewhere (or will be soon).

so, assuming $ie holds your Vapir::IE instance, you might do something like

modal_dialog_document = $ie.modal_dialog.document
a_div = modal_dialog_document.div(:id, 'some_div')
puts a_div.text

This class is not supported in IE in Ruby 1.9.1 yet.

Example Code

Here is a quick example that you can play with in an irb session:

browser=Vapir::Firefox.new # or Vapir::IE.new
browser.goto("http://www.mediacollege.com/internet/javascript/basic/alert.html")
button = browser.button(:caption, /click here/i)
button.click_no_wait  # launches the javascript alert
modal = browser.modal_dialog  # gets a reference to the javascript alert's modal dialog window 
modal.text  # what this returns depends a little on the browser version / operating system, but it will include "This is what an alert message looks like."
modal.exists?  # returns true
modal.click_button('OK') # clicks 'OK' to close the modal
modal.exists?  # the modal is gone; returns false
Something went wrong with that request. Please try again.