Class: Capybara::Selenium::SafariNode
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Node ,
Driver::Node
|
|
Instance Chain:
|
|
Inherits: |
Capybara::Selenium::Node
|
Defined in: | lib/capybara/selenium/nodes/safari_node.rb |
Constant Summary
-
MODIFIER_KEYS =
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 113%i[control left_control right_control alt left_alt right_alt shift left_shift right_shift meta left_meta right_meta command].freeze
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
Node
- Inherited
GET_XPATH_SCRIPT, OBSCURED_OR_OFFSET_SCRIPT, RAPID_APPEND_TEXT
Class Method Summary
Driver::Node
- Inherited
Instance Attribute Summary
- #disabled? ⇒ Boolean readonly
Node
- Inherited
#checked? | Alias for Node#selected?. |
#content_editable?, #disabled?, #multiple?, #readonly?, #selected?, #shadow_root, #visible?, #shadow_root? |
Driver::Node
- Inherited
Instance Method Summary
-
#click(keys = [], **options)
include Html5Drag.
- #hover
- #select_option
- #send_keys(*args)
- #set_file(value)
- #set_text(value, clear: nil, **_unused)
- #unselect_option
- #visible_text
- #_send_keys(keys, actions = browser_action, down_keys = ModifierKeysStack.new) private
Node
- Inherited
#[], #all_text, #click, #double_click, #drag_to, #drop, #hover, #obscured?, #path, #rect, #right_click, #select_option, #send_keys, | |
#set | Set the value of the form element to the given value. |
#style, #tag_name, #unselect_option, #value, #visible_text, #action_pause, #action_with_modifiers, #attrs, #auto_rapid_set_length, #boolean_attr, #bridge, #browser, #browser_action, #build_node, #capabilities, #each_key, #find_context, #modifiers_down, #modifiers_up, #native_id, #normalize_keys, #perform_with_options, | |
#select_node | a reference to the select node if this is an option node. |
#set_color, #set_content_editable, #set_date, #set_datetime_local, #set_file, #set_range, #set_text, #set_time, #sibling_index, #update_value_js, #with_file_detector |
Scroll
- Included
Find
- Included
#find_css, #find_xpath, #build_hints_js, #es_context, #filter_by_text, #find_by, #gather_hints, #is_displayed_atom |
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 |
Driver::Node
- Inherited
Constructor Details
This class inherits a constructor from Capybara::Driver::Node
Instance Attribute Details
#disabled? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 53
def disabled? driver.evaluate_script("arguments[0].matches(':disabled, select:disabled *')", self) end
Instance Method Details
#_send_keys(keys, actions = browser_action, down_keys = ModifierKeysStack.new) (private)
[ GitHub ]# File 'lib/capybara/selenium/nodes/safari_node.rb', line 93
def _send_keys(keys, actions = browser_action, down_keys = ModifierKeysStack.new) case keys when *MODIFIER_KEYS down_keys.press(keys) actions.key_down(keys) when String keys = keys.upcase if down_keys&.include?(:shift) actions.send_keys(keys) when Symbol actions.send_keys(keys) when Array 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
#click(keys = [], **options)
include Html5Drag
# File 'lib/capybara/selenium/nodes/safari_node.rb', line 9
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 rescue ::Selenium::WebDriver::Error::WebDriverError => e raise unless e.instance_of? ::Selenium::WebDriver::Error::WebDriverError # Safari doesn't return a specific error here - assume it's an ElementNotInteractableError raise ::Selenium::WebDriver::Error::ElementNotInteractableError, 'Non distinct error raised in #click, translated to ElementNotInteractableError for retry' end
#hover
[ GitHub ]# File 'lib/capybara/selenium/nodes/safari_node.rb', line 86
def hover # Workaround issue where hover would sometimes fail - possibly due to mouse not having moved scroll_if_needed { browser_action.move_to(native, 0, 0).move_to(native).perform } end
#select_option
[ GitHub ]# File 'lib/capybara/selenium/nodes/safari_node.rb', line 28
def select_option # To optimize to only one check and then click selected_or_disabled = driver.execute_script(<<~JS, self) arguments[0].closest('select').scrollIntoView(); return arguments[0].matches(':disabled, select:disabled *, :checked'); JS click unless selected_or_disabled end
#send_keys(*args)
[ GitHub ]# File 'lib/capybara/selenium/nodes/safari_node.rb', line 63
def send_keys(*args) if args.none? { |arg| arg.is_a?(Array) || (arg.is_a?(Symbol) && MODIFIER_KEYS.include?(arg)) } return super(*args.map { |arg| arg == :space ? ' ' : arg }) end native.click _send_keys(args).perform end
#set_file(value)
[ GitHub ]# File 'lib/capybara/selenium/nodes/safari_node.rb', line 57
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)
[ GitHub ]# File 'lib/capybara/selenium/nodes/safari_node.rb', line 72
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
[ GitHub ]# File 'lib/capybara/selenium/nodes/safari_node.rb', line 37
def unselect_option driver.execute_script("arguments[0].closest('select').scrollIntoView()", self) super end
#visible_text
[ GitHub ]# File 'lib/capybara/selenium/nodes/safari_node.rb', line 42
def visible_text return '' unless visible? vis_text = driver.execute_script('return arguments[0].innerText', self) vis_text.squeeze(' ') .gsub(/[\ \n]*\n[\ \n]*/, "\n") .gsub(/\A[[:space:]&&[^\u00a0]]+/, '') .gsub(/[[:space:]&&[^\u00a0]]+\z/, '') .tr("\u00a0", ' ') end