Class: Capybara::Selenium::ChromeNode
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/chrome_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
- #visible? ⇒ Boolean readonly
- #chromedriver_fixed_actions_key_state? ⇒ Boolean readonly private
- #chromedriver_supports_displayed_endpoint? ⇒ Boolean readonly private
- #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
- #drop(*args)
- #select_option
- #send_keys(*args)
- #set_file(value)
- #set_text(value, clear: nil, **_unused)
- #browser_version(to_float: true) private
- #chromedriver_version private
- #perform_legacy_drag(element, drop_modifiers) 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
#chromedriver_fixed_actions_key_state? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 108
def chromedriver_fixed_actions_key_state? Gem::Requirement.new('>= 76.0.3809.68').satisfied_by?(chromedriver_version) end
#chromedriver_supports_displayed_endpoint? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 112
def chromedriver_supports_displayed_endpoint? Gem::Requirement.new('>= 76.0.3809.25').satisfied_by?(chromedriver_version) end
#disabled? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 46
def disabled? driver.evaluate_script("arguments[0].matches(':disabled, select:disabled *')", self) end
#native_displayed? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 120
def native_displayed? (driver. [:native_displayed] != false) && chromedriver_supports_displayed_endpoint? && (!ENV['DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS']) end
#visible? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 58
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
#browser_version(to_float: true) (private)
[ GitHub ]# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 101
def browser_version(to_float: true) caps = capabilities ver = caps[:browser_version] || caps[:version] ver = ver.to_f if to_float ver end
#chromedriver_version (private)
[ GitHub ]# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 116
def chromedriver_version Gem::Version.new(capabilities['chrome']['chromedriverVersion'].split(' ')[0]) # rubocop:disable Style/RedundantArgument end
#click
[ GitHub ]# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 33
def click(*, **) super rescue ::Selenium::WebDriver::Error::ElementClickInterceptedError raise rescue ::Selenium::WebDriver::Error::WebDriverError => e # chromedriver 74 (at least on mac) raises the wrong error for this if e. .include?('element click intercepted') raise ::Selenium::WebDriver::Error::ElementClickInterceptedError, e. end raise end
#drop(*args)
[ GitHub ]# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 29
def drop(*args) html5_drop(*args) end
#perform_legacy_drag(element, drop_modifiers) (private)
# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 90
def perform_legacy_drag(element, drop_modifiers) return super if chromedriver_fixed_actions_key_state? || element.obscured? raise ArgumentError, 'Modifier keys are not supported while dragging in this version of Chrome.' unless drop_modifiers.empty? # W3C Chrome/chromedriver < 77 doesn't maintain mouse button state across actions API performs # https://bugs.chromium.org/p/chromedriver/issues/detail?id=2981 browser_action.release.perform browser_action.click_and_hold(native).move_to(element.native).release.perform end
#select_option
[ GitHub ]# File 'lib/capybara/selenium/nodes/chrome_node.rb', line 50
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/chrome_node.rb', line 70
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/chrome_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 browser_version >= 75.0 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/chrome_node.rb', line 10
def set_text(value, clear: nil, **_unused) super.tap do # React doesn't see the chromedriver element clear send_keys(:space, :backspace) if value.to_s.empty? && clear.nil? end end