Sha256: fceeda290cdc6250c463a98f5f35b4f187a787e3eaffbfa23074d79eafdcd680

Contents?: true

Size: 1.29 KB

Versions: 28

Compression:

Stored size: 1.29 KB

Contents

module Selenium
  module WebDriver

    # @api private
    class Mouse

      def initialize(bridge)
        @bridge = bridge
      end

      def click(element = nil)
        move_if_needed element
        @bridge.click
      end

      def double_click(element = nil)
        move_if_needed element
        @bridge.doubleClick
      end

      def context_click(element = nil)
        move_if_needed element
        @bridge.contextClick
      end

      def down(element = nil)
        move_if_needed element
        @bridge.mouseDown
      end

      def up(element = nil)
        move_if_needed element
        @bridge.mouseUp
      end

      #
      # Move the mouse.
      #
      # Examples:
      #
      #   driver.mouse.move_to(element)
      #   driver.mouse.move_to(element, 5, 5)
      #

      def move_to(element, right_by = nil, down_by = nil)
        unless element.kind_of? Element
          raise TypeError, "expected #{Element}, got #{element.inspect}:#{element.class}"
        end

        @bridge.mouseMoveTo element.ref, right_by, down_by
      end

      def move_by(right_by, down_by)
        @bridge.mouseMoveTo nil, right_by, down_by
      end

      private

      def move_if_needed(element)
        move_to element if element
      end

    end # Mouse
  end # WebDriver
end  # Selenium

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
selenium-webdriver-2.18.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.18.0.rc3 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.18.0.rc2 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.18.0.rc1 lib/selenium/webdriver/common/mouse.rb
bbc-selenium-webdriver-1.17.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.17.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.16.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.15.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.14.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.13.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.12.2 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.12.1 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.12.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.10.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.9.1 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.9.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.8.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.7.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.6.0 lib/selenium/webdriver/common/mouse.rb
selenium-webdriver-2.5.0 lib/selenium/webdriver/common/mouse.rb