Sha256: 7bde260e05de40b18c1cd2ae2e6368d606256c9d0cea662cf12b1baf662afc0d

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require 'aranha/selenium/driver_options'
require 'aranha/selenium/driver_factory'
require 'eac_ruby_utils/core_ext'
require 'selenium-webdriver'

module Aranha
  module Selenium
    class Session < ::SimpleDelegator
      require_sub __FILE__, include_modules: true
      enable_simple_cache

      def initialize(options = {})
        super(
          ::Aranha::Selenium::DriverFactory.create_driver(
            options.merge(::Aranha::Selenium::DriverOptions::OPTION_DOWNLOADS_DIR => downloads.dir)
          )
        )
      end

      def current_source
        element = find_element(xpath: '/html[1]')
        raise 'Root element not found' unless element

        s = element.attribute('innerHTML')
        "<html>\n#{s}\n</html>\n"
      end

      # @return [Aranha::Selenium::Session::Downloads]
      def downloads
        @downloads ||= ::Aranha::Selenium::Session::Downloads.new
      end

      private

      def element_click(element)
        element.click
        element
      rescue ::Selenium::WebDriver::Error::ElementClickInterceptedError,
             ::Selenium::WebDriver::Error::ElementNotInteractableError,
             ::Selenium::WebDriver::Error::StaleElementReferenceError
        nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aranha-selenium-0.8.0 lib/aranha/selenium/session.rb
aranha-selenium-0.7.1 lib/aranha/selenium/session.rb