Class: Watir::Alert

Inherits:
Object
  • Object
show all
Includes:
EventuallyPresent, Exception, Waitable
Defined in:
lib/watir/alert.rb

Instance Method Summary collapse

Methods included from Waitable

#wait_until, #wait_until_present, #wait_while, #wait_while_present

Methods included from EventuallyPresent

#when_enabled, #when_present

Constructor Details

#initialize(browser) ⇒ Alert

Returns a new instance of Alert.


7
8
9
10
# File 'lib/watir/alert.rb', line 7

def initialize(browser)
  @browser = browser
  @alert = nil
end

Instance Method Details

#closeObject

Closes alert or cancels prompts/confirms.

Examples:

browser.alert.close
browser.alert.exists?
#=> false

51
52
53
54
55
# File 'lib/watir/alert.rb', line 51

def close
  wait_for_exists
  @alert.dismiss
  @browser.after_hooks.run
end

#exists?Boolean Also known as: present?

Returns true if alert, confirm or prompt is present and false otherwise.

Examples:

browser.alert.exists?
#=> true

Returns:

  • (Boolean)

80
81
82
83
84
85
# File 'lib/watir/alert.rb', line 80

def exists?
  assert_exists
  true
rescue UnknownObjectException
  false
end

#okObject

Closes alert or accepts prompts/confirms.

Examples:

browser.alert.ok
browser.alert.exists?
#=> false

36
37
38
39
40
# File 'lib/watir/alert.rb', line 36

def ok
  wait_for_exists
  @alert.accept
  @browser.after_hooks.run
end

#selector_stringObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Also:


93
94
95
# File 'lib/watir/alert.rb', line 93

def selector_string
  'alert'
end

#set(value) ⇒ Object

Enters text to prompt.

Examples:

browser.alert.set "Text for prompt"
browser.alert.ok

Parameters:

  • value (String)

67
68
69
70
# File 'lib/watir/alert.rb', line 67

def set(value)
  wait_for_exists
  @alert.send_keys(value)
end

#textString

Returns text of alert.

Examples:

browser.alert.text
#=> "ok"

Returns:

  • (String)

22
23
24
25
# File 'lib/watir/alert.rb', line 22

def text
  wait_for_exists
  @alert.text
end