Module: Watir::AlertHelper
- Included in:
- Browser
- Defined in:
- lib/watir-webdriver/extensions/alerts.rb
Overview
Module provided by optional require:
require "watir-webdriver/extensions/alerts"
Instance Method Summary collapse
-
#alert(&blk) ⇒ Object
Overwrite window.alert().
-
#confirm(bool, &blk) ⇒ Object
Overwrite window.confirm().
-
#prompt(answer, &blk) ⇒ Object
Overwrite window.prompt().
Instance Method Details
#alert(&blk) ⇒ Object
Overwrite window.alert()
This method is provided by an optional require - API is subject to change.
22 23 24 25 26 |
# File 'lib/watir-webdriver/extensions/alerts.rb', line 22 def alert(&blk) execute_script "window.alert = function(msg) { window.__lastWatirAlert = msg; }" yield execute_script "return window.__lastWatirAlert" end |
#confirm(bool, &blk) ⇒ Object
Overwrite window.confirm()
This method is provided by an optional require - API is subject to change.
38 39 40 41 42 |
# File 'lib/watir-webdriver/extensions/alerts.rb', line 38 def confirm(bool, &blk) execute_script "window.confirm = function(msg) { window.__lastWatirConfirm = msg; return #{!!bool} }" yield execute_script "return window.__lastWatirConfirm" end |
#prompt(answer, &blk) ⇒ Object
Overwrite window.prompt()
This method is provided by an optional require - API is subject to change.
55 56 57 58 59 60 61 62 |
# File 'lib/watir-webdriver/extensions/alerts.rb', line 55 def prompt(answer, &blk) execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer.to_json}; }" yield result = execute_script "return window.__lastWatirPrompt" result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k)} result end |