module SeleniumRecord::Preconditions

Selenium helpers for doing an action after a precondition takes place

Public Instance Methods

when_clickable(locator) { || ... } click to toggle source

@raise [Selenium::WebDriver::Error::TimeOutError] whether the element

stays no clickable after time out period

@param locator [Hash] contains unique {key: value} where the key is the

locator_type (:class, :class_name, :css, :id, :link_text, :link,
:partial_link_text, :name, :tag_name, :xpath)

@return [Selenium::WebDriver::Element] once the element is clickable

# File lib/selenium_record/preconditions.rb, line 22
def when_clickable(locator)
  element = wait_clickable(locator)
  yield if block_given?
  element
end
when_hidden(locator) click to toggle source

@raise [Selenium::WebDriver::Error::TimeOutError] whether the element

stays visible after time out period

@param locator [Hash] contains unique {key: value} where the key is the

locator_type (:class, :class_name, :css, :id, :link_text, :link,
:partial_link_text, :name, :tag_name, :xpath)

@return [Selenium::WebDriver::Element] once the element is hidden

# File lib/selenium_record/preconditions.rb, line 38
def when_hidden(locator)
  self.class.wait_for do
    begin
      element = root_el.find_element(locator)
      element unless element.displayed?
    rescue => error
      raise if error.is_a? Selenium::WebDriver::Error::TimeOutError
      true
    end
  end
end
when_modal_present(title, &block) click to toggle source
# File lib/selenium_record/preconditions.rb, line 28
def when_modal_present(title, &block)
  when_present(:xpath, modal_header_xpath(title), &block)
end
when_present(locator) { || ... } click to toggle source

Returns the first element matching the given arguments once this element is displayed in the DOM @param how [Symbol] (:class, :class_name, :css, :id, :link_text, :link,

:partial_link_text, :name, :tag_name, :xpath)

@param what [String] @return element [Selenium::WebDriver::Element]

# File lib/selenium_record/preconditions.rb, line 10
def when_present(locator)
  element = wait_displayed(locator)
  yield if block_given?
  element
end