Class: Watir::Alert

Inherits:
Object
  • Object
show all
Includes:
ElementExtensions
Defined in:
lib/watir-classic/dialogs/alert.rb

Overview

Handle different JavaScript dialogs (alert, prompt and confirm). Returned by Container#alert.

Constant Summary collapse

WINDOW_TITLES =

JavaScript dialog titles to search for.

Examples:

When the title of your IE dialog is missing, add a new one:

Watir::Alert::WINDOW_TITLES << "My missing title"
['Message from webpage', 'Windows Internet Explorer', 'Microsoft Internet Explorer', /Mensaje de p.*/, 'Explorer User Prompt']

Instance Method Summary collapse

Methods included from ElementExtensions

#wait_until_present, #wait_while_present, #when_present

Constructor Details

#initialize(container) ⇒ Alert

Returns a new instance of Alert.



13
14
15
# File 'lib/watir-classic/dialogs/alert.rb', line 13

def initialize(container)
  @container = container
end

Instance Method Details

#closeObject

Close the JavaScript dialog.



25
26
27
28
# File 'lib/watir-classic/dialogs/alert.rb', line 25

def close
  dialog.close
  wait_until_not_exists
end

#exists?Boolean Also known as: present?

Returns true when JavaScript dialog exists and is visible, false otherwise.

Returns:

  • (Boolean)

    true when JavaScript dialog exists and is visible, false otherwise.



18
19
20
# File 'lib/watir-classic/dialogs/alert.rb', line 18

def exists?
  dialog.present?
end

#okObject

Press the “OK” button on the JavaScript dialog.



36
37
38
39
# File 'lib/watir-classic/dialogs/alert.rb', line 36

def ok
  dialog.button(:value => "OK").click
  wait_until_not_exists
end

#set(text) ⇒ Object

Set the text on the JavaScript prompt dialog.

Parameters:

  • text (String)

    text to set.



43
44
45
# File 'lib/watir-classic/dialogs/alert.rb', line 43

def set(text)
  dialog.text_field.set text
end

#textString

Returns the visible text of the JavaScript dialog.

Returns:

  • (String)

    the visible text of the JavaScript dialog.



31
32
33
# File 'lib/watir-classic/dialogs/alert.rb', line 31

def text
  dialog.text
end