Sha256: 00bd4c165da1e7b0977d6f2a5d2a5202fda92fe93525f4e85047d3d7019be091

Contents?: true

Size: 1.68 KB

Versions: 10

Compression:

Stored size: 1.68 KB

Contents

module Watir
  class Alert

    include EventuallyPresent

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

    #
    # Returns text of alert.
    #
    # @example
    #   browser.alert.text
    #   #=> "ok"
    #
    # @return [String]
    #

    def text
      assert_exists
      @alert.text
    end

    #
    # Closes alert or accepts prompts/confirms.
    #
    # @example
    #   browser.alert.ok
    #   browser.alert.exists?
    #   #=> false
    #

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

    #
    # Closes alert or cancels prompts/confirms.
    #
    # @example
    #   browser.alert.close
    #   browser.alert.exists?
    #   #=> false
    #

    def close
      assert_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)
      assert_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 Exception::UnknownObjectException
      false
    end
    alias_method :present?, :exists?

    #
    # @api private
    #

    def selector_string
      'alert'
    end

    private

    def assert_exists
      @alert = @browser.driver.switch_to.alert
    rescue Selenium::WebDriver::Error::NoAlertPresentError
      raise Exception::UnknownObjectException, 'unable to locate alert'
    end

  end # Alert
end # Watir

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
watir-webdriver-0.9.9 lib/watir-webdriver/alert.rb
watir-6.0.0.beta5 lib/watir/alert.rb
watir-6.0.0.beta4 lib/watir/alert.rb
watir-6.0.0.beta3 lib/watir/alert.rb
watir-6.0.0.beta2 lib/watir/alert.rb
watir-6.0.0.beta1 lib/watir/alert.rb
watir-webdriver-0.9.3 lib/watir-webdriver/alert.rb
watir-webdriver-0.9.2 lib/watir-webdriver/alert.rb
watir-webdriver-0.9.1 lib/watir-webdriver/alert.rb
watir-webdriver-0.9.0 lib/watir-webdriver/alert.rb