Sha256: 9a1184d0bb7aa32ee675b821393051ec49eb39abb80cfc2ac2103dc75ac2acda
Contents?: true
Size: 1.92 KB
Versions: 4
Compression:
Stored size: 1.92 KB
Contents
# frozen_string_literal: true module Watir class Alert include Waitable include Exception def initialize(browser) @browser = browser @alert = nil end # # Returns text of alert. # # @example # browser.alert.text # #=> "ok" # # @return [String] # def text wait_for_exists @alert.text end # # Closes alert or accepts prompts/confirms. # # @example # browser.alert.ok # browser.alert.exists? # #=> false # def ok wait_for_exists @alert.accept @browser.after_hooks.run end # # Closes alert or cancels prompts/confirms. # # @example # browser.alert.close # browser.alert.exists? # #=> false # def close wait_for_exists @alert.dismiss @browser.after_hooks.run end # # Enters text to prompt. # # @example # browser.alert.set "Text for prompt" # browser.alert.ok # # @param [String] value # def set(value) wait_for_exists @alert.send_keys(value) end # # Returns true if alert, confirm or prompt is present and false otherwise. # # @example # browser.alert.exists? # #=> true # def exists? assert_exists true rescue UnknownObjectException false end alias present? exists? alias exist? exists? # # @api private # @see Watir::Wait # def selector_string 'alert' end private def assert_exists @alert = @browser.driver.switch_to.alert rescue Selenium::WebDriver::Error::NoSuchAlertError raise UnknownObjectException, 'unable to locate alert' end def wait_for_exists wait_until(message: 'waiting for alert', &:exists?) rescue Wait::TimeoutError raise UnknownObjectException, 'unable to locate alert' end end # Alert end # Watir
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
watir-7.3.0 | lib/watir/alert.rb |
watir-7.2.2 | lib/watir/alert.rb |
watir-7.2.1 | lib/watir/alert.rb |
watir-7.2.0 | lib/watir/alert.rb |