Sha256: 1dd1f2da3b4114c3a46309b0ddd5cc648e6ed5b2bd9531f0cfe0bb7f7422dab1

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

module Watir
  # Handle different JavaScript dialogs (alert, prompt and confirm).
  # Returned by {Container#alert}.
  class Alert
    include ElementExtensions

    # JavaScript dialog titles to search for.
    #
    # @example When the title of your IE dialog is missing, add a new one:
    #   Watir::Alert::WINDOW_TITLES << "My missing title"
    WINDOW_TITLES = ['Message from webpage', 'Windows Internet Explorer', 'Microsoft Internet Explorer', /Mensaje de p.*/, 'Explorer User Prompt']

    def initialize(container)
      @container = container
    end

    # @return [Boolean] true when JavaScript dialog exists and is visible, false otherwise.
    def exists?
      dialog.present?
    end

    alias_method :present?, :exists?

    # Close the JavaScript dialog.
    def close
      dialog.close
      wait_until_not_exists
    end

    # @return [String] the visible text of the JavaScript dialog.
    def text
      dialog.text
    end

    # Press the "OK" button on the JavaScript dialog.
    def ok
      dialog.button(:value => "OK").click
      wait_until_not_exists
    end

    # Set the text on the JavaScript prompt dialog.
    # @param [String] text text to set.
    def set(text)
      dialog.text_field.set text
    end

    private 

    def dialog
      @window ||= RAutomation::Window.new(:hwnd => @container.hwnd).child(:title => Regexp.new("^#{Regexp.union WINDOW_TITLES}$", Regexp::IGNORECASE))
    end

    def wait_until_not_exists
      Wait.until(3) {!exists?}
      @container.page_container.wait
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
watir-classic-4.3.0 lib/watir-classic/dialogs/alert.rb
watir-classic-4.2.0 lib/watir-classic/dialogs/alert.rb
watir-classic-4.1.0 lib/watir-classic/dialogs/alert.rb
watir-classic-4.0.1 lib/watir-classic/dialogs/alert.rb
watir-classic-4.0.0 lib/watir-classic/dialogs/alert.rb
watir-classic-3.7.0 lib/watir-classic/dialogs/alert.rb
watir-classic-3.6.0 lib/watir-classic/dialogs/alert.rb
watir-classic-3.5.0 lib/watir-classic/dialogs/alert.rb