Class: Capybara::Selenium::MarionetteNode

Inherits:
Node show all
Includes:
Html5Drag
Defined in:
lib/capybara/selenium/nodes/marionette_node.rb

Instance Attribute Summary

Attributes inherited from Driver::Node

#driver, #native

Instance Method Summary collapse

Methods inherited from Node

#==, #[], #all_text, #content_editable?, #double_click, #find_css, #find_xpath, #hover, #multiple?, #path, #readonly?, #right_click, #select_option, #selected?, #set, #style, #tag_name, #unselect_option, #value, #visible?, #visible_text

Methods inherited from Driver::Node

#==, #[], #all_text, #checked?, #double_click, #hover, #initialize, #inspect, #multiple?, #path, #readonly?, #right_click, #select_option, #selected?, #set, #style, #tag_name, #trigger, #unselect_option, #value, #visible?, #visible_text

Constructor Details

This class inherits a constructor from Capybara::Driver::Node

Instance Method Details

#click(keys = [], **options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/capybara/selenium/nodes/marionette_node.rb', line 8

def click(keys = [], **options)
  super
rescue ::Selenium::WebDriver::Error::ElementNotInteractableError
  if tag_name == 'tr'
    warn 'You are attempting to click a table row which has issues in geckodriver/marionette - see https://github.com/mozilla/geckodriver/issues/1228. ' \
         'Your test should probably be clicking on a table cell like a user would. Clicking the first cell in the row instead.'
    return find_css('th:first-child,td:first-child')[0].click(keys, options)
  end
  raise
end

#disabled?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/capybara/selenium/nodes/marionette_node.rb', line 19

def disabled?
  # Not sure exactly what version of FF fixed the below issue, but it is definitely fixed in 61+
  return super unless browser_version < 61.0

  return true if super

  # workaround for selenium-webdriver/geckodriver reporting elements as enabled when they are nested in disabling elements
  if %w[option optgroup].include? tag_name
    find_xpath('parent::*[self::optgroup or self::select]')[0].disabled?
  else
    !find_xpath('parent::fieldset[@disabled] | ancestor::*[not(self::legend) or preceding-sibling::legend][parent::fieldset[@disabled]]').empty?
  end
end

#drag_to(element) ⇒ Object



54
55
56
57
58
# File 'lib/capybara/selenium/nodes/marionette_node.rb', line 54

def drag_to(element)
  return super unless (browser_version >= 62.0) && html5_draggable?

  html5_drag_to(element)
end

#send_keys(*args) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/capybara/selenium/nodes/marionette_node.rb', line 46

def send_keys(*args)
  # https://github.com/mozilla/geckodriver/issues/846
  return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none? { |arg| arg.is_a? Array }

  native.click
  _send_keys(args).perform
end

#set_file(value) ⇒ Object

rubocop:disable Naming/AccessorMethodName



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/capybara/selenium/nodes/marionette_node.rb', line 33

def set_file(value) # rubocop:disable Naming/AccessorMethodName
  # By default files are appended so we have to clear here if its multiple and already set
  native.clear if multiple? && driver.evaluate_script('arguments[0].files', self).any?
  return super if browser_version >= 62.0

  # Workaround lack of support for multiple upload by uploading one at a time
  path_names = value.to_s.empty? ? [] : Array(value)
  if (fd = bridge.file_detector) && !driver.browser.respond_to?(:upload)
    path_names.map! { |path| upload(fd.call([path])) || path }
  end
  path_names.each { |path| native.send_keys(path) }
end