Class: Watir::Alert

Inherits:
Object
  • Object
show all
Includes:
EventuallyPresent
Defined in:
lib/watir-webdriver/alert.rb

Instance Method Summary collapse

Methods included from EventuallyPresent

#wait_until_present, #wait_while_present, #when_present

Constructor Details

#initialize(target_locator) ⇒ Alert

Returns a new instance of Alert.



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

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

Instance Method Details

#closeObject

Closes alert or cancels prompts/confirms.

Examples:

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


50
51
52
53
# File 'lib/watir-webdriver/alert.rb', line 50

def close
  assert_exists
  @alert.dismiss
end

#exists?Boolean Also known as: present?

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

Returns:

  • (Boolean)


74
75
76
77
78
79
# File 'lib/watir-webdriver/alert.rb', line 74

def exists?
  assert_exists
  true
rescue Exception::UnknownObjectException
  false
end

#okObject

Closes alert or accepts prompts/confirms.

Examples:

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


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

def ok
  assert_exists
  @alert.accept
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.



86
87
88
# File 'lib/watir-webdriver/alert.rb', line 86

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)


65
66
67
68
# File 'lib/watir-webdriver/alert.rb', line 65

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

#textString

Returns text of alert.

Examples:

browser.alert.text
#=> "This is alert text"

Returns:

  • (String)


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

def text
  assert_exists
  @alert.text
end