lib/capybara/selenium/nodes/marionette_node.rb in capybara-3.8.2 vs lib/capybara/selenium/nodes/marionette_node.rb in capybara-3.9.0
- old
+ new
@@ -19,10 +19,11 @@
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?
@@ -50,17 +51,16 @@
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
- args.each_with_object(browser_action) do |keys, actions|
- _send_keys(keys, actions)
- end.perform
+ _send_keys(args).perform
end
def drag_to(element)
return super unless (browser_version >= 62.0) && html5_draggable?
+
html5_drag_to(element)
end
private
@@ -69,39 +69,33 @@
# scroll element to middle just in case
scroll_to_center if click_options.coords?
super
end
- def _send_keys(keys, actions, down_keys = nil)
+ def _send_keys(keys, actions = browser_action, down_keys = ModifierKeysStack.new)
case keys
- when String
- keys = keys.upcase if down_keys&.include?(:shift) # https://bugzilla.mozilla.org/show_bug.cgi?id=1405370
- actions.send_keys(keys)
- when :space
- actions.send_keys(' ') # https://github.com/mozilla/geckodriver/issues/846
when :control, :left_control, :right_control,
:alt, :left_alt, :right_alt,
:shift, :left_shift, :right_shift,
:meta, :left_meta, :right_meta,
:command
- if down_keys.nil?
- actions.send_keys(keys)
- else
- down_keys << keys
- actions.key_down(keys)
- end
+ down_keys.press(keys)
+ actions.key_down(keys)
+ when String
+ # https://bugzilla.mozilla.org/show_bug.cgi?id=1405370
+ keys = keys.upcase if (browser_version < 64.0) && down_keys&.include?(:shift)
+ actions.send_keys(keys)
when Symbol
actions.send_keys(keys)
when Array
- local_down_keys = []
- keys.each do |sub_keys|
- _send_keys(sub_keys, actions, local_down_keys)
- end
- local_down_keys.each { |key| actions.key_up(key) }
+ down_keys.push
+ keys.each { |sub_keys| _send_keys(sub_keys, actions, down_keys) }
+ down_keys.pop.reverse_each { |key| actions.key_up(key) }
else
raise ArgumentError, 'Unknown keys type'
end
+ actions
end
def bridge
driver.browser.send(:bridge)
end
@@ -116,6 +110,29 @@
end
def browser_version
driver.browser.capabilities[:browser_version].to_f
end
+
+ class ModifierKeysStack
+ def initialize
+ @stack = []
+ end
+
+ def include?(key)
+ @stack.flatten.include?(key)
+ end
+
+ def press(key)
+ @stack.last.push(key)
+ end
+
+ def push
+ @stack.push []
+ end
+
+ def pop
+ @stack.pop
+ end
+ end
+ private_constant :ModifierKeysStack
end