Sha256: 8d87d95fd8bf1f14997ca2932998a0ecd4206dd6c7d1a46431a5615c56769435

Contents?: true

Size: 1.59 KB

Versions: 10

Compression:

Stored size: 1.59 KB

Contents

# encoding: utf-8
module Watir
  class Alert

    include EventuallyPresent

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

    #
    # Returns text of alert.
    #
    # @example
    #   browser.alert.text
    #   #=> "This is alert text"
    #
    # @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
    end

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

    def close
      assert_exists
      @alert.dismiss
    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.
    #

    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 = @target_locator.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 & 1 rubygems

Version Path
watir-webdriver-0.6.11 lib/watir-webdriver/alert.rb
watir-webdriver-0.6.10 lib/watir-webdriver/alert.rb
watir-webdriver-0.6.9 lib/watir-webdriver/alert.rb
watir-webdriver-0.6.8 lib/watir-webdriver/alert.rb
watir-webdriver-0.6.7 lib/watir-webdriver/alert.rb
watir-webdriver-0.6.6 lib/watir-webdriver/alert.rb
watir-webdriver-0.6.5 lib/watir-webdriver/alert.rb
watir-webdriver-0.6.4 lib/watir-webdriver/alert.rb
watir-webdriver-0.6.3 lib/watir-webdriver/alert.rb
watir-webdriver-0.6.2 lib/watir-webdriver/alert.rb