class Watir::Alert
Public Class Methods
new(browser)
click to toggle source
# File lib/watir-webdriver/alert.rb, line 6 def initialize(browser) @browser = browser @alert = nil end
Public Instance Methods
close()
click to toggle source
Closes alert or cancels prompts/confirms.
@example
browser.alert.close browser.alert.exists? #=> false
# File lib/watir-webdriver/alert.rb, line 50 def close assert_exists @alert.dismiss @browser.after_hooks.run end
exists?()
click to toggle source
Returns true if alert, confirm or prompt is present and false otherwise.
@example
browser.alert.exists? #=> true
# File lib/watir-webdriver/alert.rb, line 79 def exists? assert_exists true rescue Exception::UnknownObjectException false end
Also aliased as: present?
ok()
click to toggle source
Closes alert or accepts prompts/confirms.
@example
browser.alert.ok browser.alert.exists? #=> false
# File lib/watir-webdriver/alert.rb, line 35 def ok assert_exists @alert.accept @browser.after_hooks.run end
selector_string()
click to toggle source
@api private
# File lib/watir-webdriver/alert.rb, line 91 def selector_string 'alert' end
set(value)
click to toggle source
Enters text to prompt.
@example
browser.alert.set "Text for prompt" browser.alert.ok
@param [String] value
# File lib/watir-webdriver/alert.rb, line 66 def set(value) assert_exists @alert.send_keys(value) end
text()
click to toggle source
Returns text of alert.
@example
browser.alert.text #=> "ok"
@return [String]
# File lib/watir-webdriver/alert.rb, line 21 def text assert_exists @alert.text end
Private Instance Methods
assert_exists()
click to toggle source
# File lib/watir-webdriver/alert.rb, line 97 def assert_exists @alert = @browser.driver.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertPresentError raise Exception::UnknownObjectException, 'unable to locate alert' end