Class: Capybara::Selenium::EdgeNode

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

Instance Attribute Summary

Attributes inherited from Driver::Node

#driver, #initial_cache, #native

Instance Method Summary collapse

Methods inherited from Node

#==, #[], #all_text, #content_editable?, #double_click, #drag_to, #hover, #multiple?, #obscured?, #path, #readonly?, #rect, #right_click, #selected?, #send_keys, #set, #style, #tag_name, #unselect_option, #value, #visible_text

Methods included from Scroll

#scroll_by, #scroll_to

Methods included from Find

#find_css, #find_xpath

Methods inherited from Driver::Node

#==, #[], #all_text, #checked?, #double_click, #drag_to, #hover, #initialize, #inspect, #multiple?, #obscured?, #path, #readonly?, #rect, #right_click, #scroll_by, #scroll_to, #selected?, #send_keys, #set, #style, #tag_name, #trigger, #unselect_option, #value, #visible_text

Constructor Details

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

Instance Method Details

#clickObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 41

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

#disabled?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 52

def disabled?
  return super unless chrome_edge?

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

#drop(*args) ⇒ Object



35
36
37
38
39
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 35

def drop(*args)
  return super unless chrome_edge?

  html5_drop(*args)
end

#select_optionObject



58
59
60
61
62
63
64
65
66
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 58

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

#set_file(value) ⇒ Object

rubocop:disable Naming/AccessorMethodName



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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
rescue *file_errors => e
  if e.message.match?(/File not found : .+\n.+/m)
    raise ArgumentError, "Selenium < 3.14 with remote Chrome doesn't support multiple file upload"
  end

  raise
end

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



8
9
10
11
12
13
14
15
# 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

#visible?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/capybara/selenium/nodes/edge_node.rb', line 68

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

  begin
    bridge.send(:execute, :is_element_displayed, id: native.ref)
  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