Class: Capybara::Selenium::SafariNode
- Inherits:
-
Node
- Object
- Driver::Node
- Node
- Capybara::Selenium::SafariNode
- Defined in:
- lib/capybara/selenium/nodes/safari_node.rb
Overview
require ‘capybara/selenium/extensions/html5_drag’
Instance Attribute Summary
Attributes inherited from Driver::Node
#driver, #initial_cache, #native
Instance Method Summary collapse
-
#click(keys = [], **options) ⇒ Object
include Html5Drag.
- #disabled? ⇒ Boolean
- #select_option ⇒ Object
- #send_keys(*args) ⇒ Object
-
#set_file(value) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #set_text(value, clear: nil, **_unused) ⇒ Object
- #unselect_option ⇒ Object
- #visible_text ⇒ Object
Methods inherited from Node
#==, #[], #all_text, #content_editable?, #double_click, #drag_to, #hover, #multiple?, #path, #readonly?, #right_click, #selected?, #set, #style, #tag_name, #value, #visible?
Methods included from Scroll
Methods included from Find
Methods inherited from Driver::Node
#==, #[], #all_text, #checked?, #double_click, #drag_to, #hover, #initialize, #inspect, #multiple?, #path, #readonly?, #right_click, #scroll_by, #scroll_to, #selected?, #set, #style, #tag_name, #trigger, #value, #visible?
Constructor Details
This class inherits a constructor from Capybara::Driver::Node
Instance Method Details
#click(keys = [], **options) ⇒ Object
include Html5Drag
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 8 def click(keys = [], **) # driver.execute_script('arguments[0].scrollIntoViewIfNeeded({block: "center"})', self) super rescue ::Selenium::WebDriver::Error::ElementNotInteractableError if tag_name == 'tr' warn 'You are attempting to click a table row which has issues in safaridriver - '\ '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, ) end raise end |
#disabled? ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 42 def disabled? return true if super # workaround for safaridriver reporting elements as enabled when they are nested in disabling elements if %w[option optgroup].include? tag_name return true if self[:disabled] == 'true' find_xpath('parent::*[self::optgroup or self::select]')[0].disabled? else !find_xpath(DISABLED_BY_FIELDSET_XPATH).empty? end end |
#select_option ⇒ Object
21 22 23 24 |
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 21 def select_option driver.execute_script("arguments[0].closest('select').scrollIntoView()", self) super end |
#send_keys(*args) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 61 def send_keys(*args) 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
55 56 57 58 59 |
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 55 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? super end |
#set_text(value, clear: nil, **_unused) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 68 def set_text(value, clear: nil, **_unused) value = value.to_s if clear == :backspace # Clear field by sending the correct number of backspace keys. backspaces = [:backspace] * self.value.to_s.length send_keys(*([[:control, 'e']] + backspaces + [value])) else super.tap do # React doesn't see the safaridriver element clear send_keys(:space, :backspace) if value.to_s.empty? && clear.nil? end end end |
#unselect_option ⇒ Object
26 27 28 29 |
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 26 def unselect_option driver.execute_script("arguments[0].closest('select').scrollIntoView()", self) super end |
#visible_text ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 31 def visible_text return '' unless visible? vis_text = driver.execute_script('return arguments[0].innerText', self) vis_text.gsub(/\ +/, ' ') .gsub(/[\ \n]*\n[\ \n]*/, "\n") .gsub(/\A[[:space:]&&[^\u00a0]]+/, '') .gsub(/[[:space:]&&[^\u00a0]]+\z/, '') .tr("\u00a0", ' ') end |