Module: Robro::Browser::Helpers

Included in:
Robro::Browser
Defined in:
lib/robro/browser/helpers.rb

Instance Method Summary collapse

Instance Method Details

#click_through_overlay(element) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/robro/browser/helpers.rb', line 8

def click_through_overlay(element)
  element_regexp = {
    firefox: /^Element (<.*>) is not clickable at point \((\d+),(\d+)\) because another element (?<element><.*>) obscures it$/,
    chrome: /^element click intercepted: Element (<.*>) is not clickable at point \((\d+), (\d+)\)\. Other element would receive the click: (?<element><.*>)/,
  }
  loop do
    element.click(wait: 1)
    break
  rescue StandardError => e
    m_element = element_regexp[Robro.browser.application].match e.message
    unless m_element.nil?
      m_id = /id=\"(?<id>[a-zA-Z0-9-]+)/.match m_element[:element]
      unless m_id.nil?
        overlay_element_id = m_id[:id]
        Robro.logger.debug "Removing '#{overlay_element_id}' that obscures target element"
        remove_elements css: "##{overlay_element_id}"
      else
        Robro.logger.error "Unable to find element ID that obscures target (#{element}) in: '#{m_id[:element]}'"
        debugger
      end
    else
      Robro.logger.error "Unable to find element that obscures target (#{element}) in: '#{e.message}'"
      debugger
    end
  end
end

#remove_elements(css:) ⇒ Object



4
5
6
# File 'lib/robro/browser/helpers.rb', line 4

def remove_elements(css:)
  page.execute_script "document.querySelectorAll('#{css}').forEach(e => { e.remove() } )"
end