Class: Capybara::Selenium::FirefoxNode
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Node ,
Driver::Node
|
|
Instance Chain:
self,
FileInputClickEmulation,
Html5Drag,
Node ,
Scroll ,
Find ,
Node::WhitespaceNormalizer ,
Driver::Node
|
|
Inherits: |
Capybara::Selenium::Node
|
Defined in: | lib/capybara/selenium/nodes/firefox_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
Node
- Inherited
GET_XPATH_SCRIPT, OBSCURED_OR_OFFSET_SCRIPT, RAPID_APPEND_TEXT
Class Method Summary
Driver::Node
- Inherited
Instance Attribute Summary
- #disabled? ⇒ Boolean readonly
- #focused? ⇒ Boolean readonly
- #visible? ⇒ Boolean readonly
- #native_displayed? ⇒ Boolean readonly private
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)
- #drop(*args)
- #hover
- #select_option
- #send_keys(*args)
- #set_file(value)
- #_send_keys(keys, actions = browser_action, down_keys = ModifierKeysStack.new) private
- #browser_version private
- #perform_with_options(click_options) private
- #upload(local_file) 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/firefox_node.rb', line 22
def disabled? driver.evaluate_script("arguments[0].matches(':disabled, select:disabled *')", self) end
#focused? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 43
def focused? driver.evaluate_script('arguments[0] == document.activeElement', self) end
#native_displayed? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 89
def native_displayed? (driver. [:native_displayed] != false) && !ENV['DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS'] end
#visible? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 75
def visible? return super unless 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. [:native_displayed] = false super end end
Instance Method Details
#_send_keys(keys, actions = browser_action, down_keys = ModifierKeysStack.new) (private)
[ GitHub ]# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 100
def _send_keys(keys, actions = browser_action, down_keys = ModifierKeysStack.new) case keys when :control, :left_control, :right_control, :alt, :left_alt, :right_alt, :shift, :left_shift, :right_shift, :, :, :, :command 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 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
#browser_version (private)
[ GitHub ]# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 133
def browser_version driver.browser.capabilities[:browser_version].to_f end
#click(keys = [], **options)
[ GitHub ]# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 10
def click(keys = [], ** ) super rescue ::Selenium::WebDriver::Error::ElementNotInteractableError if tag_name == 'tr' warn 'You are attempting to click a table row which has issues in geckodriver/marionette - ' \ 'see https://github.com/mozilla/geckodriver/issues/1228 - 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
#drop(*args)
[ GitHub ]# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 56
def drop(*args) html5_drop(*args) end
#hover
[ GitHub ]# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 60
def hover return super unless browser_version >= 65.0 # work around issue 2156 - https://github.com/teamcapybara/capybara/issues/2156 scroll_if_needed { browser_action.move_to(native, 0, 0).move_to(native).perform } end
#perform_with_options(click_options) (private)
[ GitHub ]# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 93
def ( ) # Firefox/marionette has an issue clicking with offset near viewport edge # scroll element to middle just in case scroll_to_center if .coords? super end
#select_option
[ GitHub ]# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 67
def select_option # 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/firefox_node.rb', line 47
def send_keys(*args) # https://github.com/mozilla/geckodriver/issues/846 return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none?(Array) native.click unless focused? _send_keys(args).perform end
#set_file(value)
[ GitHub ]# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 26
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 driver.execute_script(<<~JS, self) if (arguments[0].multiple && arguments[0].files.length){ arguments[0].value = null; } JS return super if browser_version >= 62.0 # Workaround lack of support for multiple upload by uploading one at a time path_names = value.to_s.empty? ? [] : Array(value) if (fd = bridge.file_detector) && !driver.browser.respond_to?(:upload) path_names.map! { |path| upload(fd.call([path])) || path } end path_names.each { |path| native.send_keys(path) } end
#upload(local_file) (private)
# File 'lib/capybara/selenium/nodes/firefox_node.rb', line 125
def upload(local_file) return nil unless local_file raise ArgumentError, "You may only upload files: #{local_file.inspect}" unless File.file?(local_file) file = ::Selenium::WebDriver::Zipper.zip_file(local_file) bridge.http.call(:post, "session/#{bridge.session_id}/file", file: file)['value'] end