module LapisLazuli::BrowserModule::Interaction

Module with helper functions to do with DOM element interaction

Constants

DEFAULT_CLICK_TYPES

Click types

Public Instance Methods

click_type(elem, type) click to toggle source

Combination of elem.click, on_click and js_click: uses the click method given as the second parameter; may be one of :method, :event, :js.

# File lib/lapis_lazuli/browser/interaction.rb, line 42
def click_type(elem, type)
  type = type.to_sym
  assert DEFAULT_CLICK_TYPES.include?(type), "Not a valid click type: #{type}"

  case type
  when :method
    elem.click
  when :event
    on_click(elem)
  when :js
    js_click(elem)
  end
end
click_types(elem, types = DEFAULT_CLICK_TYPES) click to toggle source

Forces clicking by trying any of the given types of click on the given element, until one succeeds. If all fail, the corresponding errors are raised as an Array

# File lib/lapis_lazuli/browser/interaction.rb, line 61
def click_types(elem, types = DEFAULT_CLICK_TYPES)
  errors = []
  types.each do |type|
    begin
      click_type(elem, type)
    rescue RuntimeError => err
      errors << err
    end
  end

  if errors.length > 0
    world.error("Could not click #{elem} given any of these click types: #{types}: #{errors}")
  end
end
force_click(*args) click to toggle source

Tries the default click types on all elements passed to it.

# File lib/lapis_lazuli/browser/interaction.rb, line 79
def force_click(*args)
  elems = make_list_from_nested(args)

  elems.each do |elem|
    click_types(elem, DEFAULT_CLICK_TYPES)
  end
end
js_click(elem) click to toggle source

Given an element, uses JavaScript to click it.

# File lib/lapis_lazuli/browser/interaction.rb, line 34
def js_click(elem)
  self.execute_script('arguments[0].click();', elem)
end
on_click(elem) click to toggle source

Given an element, fires a click event on it.

# File lib/lapis_lazuli/browser/interaction.rb, line 27
def on_click(elem)
  elem.fire_event('onClick')
end