Sha256: 234c8377e0a16990ddd60bbc7a8e1d427d6d205f2a676102d91329351a7e3cb7

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Aranha
  module Selenium
    class Session < ::SimpleDelegator
      class Element
        common_constructor :session, :find_args

        # @return [Boolean]
        def click
          click!
          true
        rescue ::Selenium::WebDriver::Error::ElementClickInterceptedError,
               ::Selenium::WebDriver::Error::ElementNotInteractableError,
               ::Selenium::WebDriver::Error::NoSuchElementError,
               ::Selenium::WebDriver::Error::StaleElementReferenceError
          false
        end

        # @return [self]
        # @raise [Selenium::WebDriver::Error::ElementClickInterceptedError]
        # @raise [Selenium::WebDriver::Error::ElementNotInteractableError]
        # @raise [Selenium::WebDriver::Error::NoSuchElementError]
        # @raise [Selenium::WebDriver::Error::StaleElementReferenceError]
        def click!
          find!.click

          self
        end

        # @return [Selenium::WebDriver::Element, nil]
        def find
          r = session.find_elements(*find_args)
          r.any? ? r.first : nil
        end

        # @return [Selenium::WebDriver::Element]
        # @raise [Selenium::WebDriver::Error::NoSuchElementError]
        def find!
          return find_args.first if find_args.count >= 1 &&
                                    find_args.first.is_a?(::Selenium::WebDriver::Element)

          session.__getobj__.find_element(*find_args)
        end

        # @param session_wait_args [Array] Arguments for +Aranha::Selenium::Session::Wait.wait+.
        # @return [self]
        def wait_click(*session_wait_args, &block)
          session.wait(*session_wait_args).until do
            block.if_present(&:call)
            click
          end
          self
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aranha-selenium-0.11.1 lib/aranha/selenium/session/element.rb
aranha-selenium-0.11.0 lib/aranha/selenium/session/element.rb