123456789_123456789_123456789_123456789_123456789_

Class: Capybara::Selenium::EdgeNode

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Capybara::Selenium::Node
Defined in: lib/capybara/selenium/nodes/edge_node.rb

Constant Summary

Node::WhitespaceNormalizer - Included

BREAKING_SPACES, EMPTY_LINES, LEADING_SPACES, LEFT_TO_RIGHT_MARK, LINE_SEPERATOR, NON_BREAKING_SPACE, PARAGRAPH_SEPERATOR, REMOVED_CHARACTERS, RIGHT_TO_LEFT_MARK, SQUEEZED_SPACES, TRAILING_SPACES, ZERO_WIDTH_SPACE

Scroll - Included

SCROLL_POSITIONS

Node - Inherited

GET_XPATH_SCRIPT, OBSCURED_OR_OFFSET_SCRIPT, RAPID_APPEND_TEXT

Class Method Summary

Driver::Node - Inherited

Instance Attribute Summary

Instance Method Summary

Node - Inherited

Scroll - Included

Find - Included

Node::WhitespaceNormalizer - Included

#normalize_spacing

Normalizes the spacing of a node’s text to be similar to what matchers might expect.

#normalize_visible_spacing

Variant on Capybara::Node::Normalizer#normalize_spacing that targets the whitespace of visible elements only.

Driver::Node - Inherited

Constructor Details

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

Instance Attribute Details

#chrome_edge?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 101

def chrome_edge?
  browser_version >= 75
end

#disabled?Boolean (readonly)

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 46

def disabled?
  return super unless chrome_edge?

  driver.evaluate_script("arguments[0].matches(':disabled, select:disabled *')", self)
end

#native_displayed?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 105

def native_displayed?
  (driver.options[:native_displayed] != false) &&
    # chromedriver_supports_displayed_endpoint? &&
    (!ENV['DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS'])
end

#visible?Boolean (readonly)

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 62

def visible?
  return super unless chrome_edge? && native_displayed?

  begin
    bridge.send(:execute, :is_element_displayed, id: native_id)
  rescue Selenium::WebDriver::Error::UnknownCommandError
    # If the is_element_displayed command is unknown, no point in trying again
    driver.options[:native_displayed] = false
    super
  end
end

Instance Method Details

#browser_version (private)

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 94

def browser_version
  @browser_version ||= begin
    caps = driver.browser.capabilities
    (caps[:browser_version] || caps[:version]).to_f
  end
end

#click

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 35

def click(*, **)
  super
rescue Selenium::WebDriver::Error::InvalidArgumentError => e
  tag_name, type = attrs(:tagName, :type).map { |val| val&.downcase }
  if tag_name == 'input' && type == 'file'
    raise Selenium::WebDriver::Error::InvalidArgumentError, "EdgeChrome can't click on file inputs.\n#{e.message}"
  end

  raise
end

#drop(*args)

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 29

def drop(*args)
  return super unless chrome_edge?

  html5_drop(*args)
end

#select_option

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 52

def select_option
  return super unless chrome_edge?

  # To optimize to only one check and then click
  selected_or_disabled = driver.evaluate_script(<<~JS, self)
    arguments[0].matches(':disabled, select:disabled *, :checked')
  JS
  click unless selected_or_disabled
end

#send_keys(*args)

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 74

def send_keys(*args)
  args.chunk { |inp| inp.is_a?(String) && inp.match?(/\p{Emoji Presentation}/) }
      .each do |contains_emoji, inputs|
    if contains_emoji
      inputs.join.grapheme_clusters.chunk { |gc| gc.match?(/\p{Emoji Presentation}/) }
            .each do |emoji, clusters|
        if emoji
          driver.send(:execute_cdp, 'Input.insertText', text: clusters.join)
        else
          super(clusters.join)
        end
      end
    else
      super(*inputs)
    end
  end
end

#set_file(value)

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 17

def set_file(value) # rubocop:disable Naming/AccessorMethodName
  # In Chrome 75+ files are appended (due to WebDriver spec - why?) so we have to clear here if its multiple and already set
  if chrome_edge?
    driver.execute_script(<<~JS, self)
      if (arguments[0].multiple && arguments[0].files.length){
        arguments[0].value = null;
      }
    JS
  end
  super
end

#set_text(value, clear: nil, **_unused)

[ GitHub ]

  
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 8

def set_text(value, clear: nil, **_unused)
  return super unless chrome_edge?

  super.tap do
    # React doesn't see the chromedriver element clear
    send_keys(:space, :backspace) if value.to_s.empty? && clear.nil?
  end
end