Sha256: 010eecf2054007eea7ec2132df938d1ee203a5b4b74c34124746f97498e556bc
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node def set_file(value) # rubocop:disable Naming/AccessorMethodName super(value) rescue ::Selenium::WebDriver::Error::ExpectedError => err if err.message =~ /File not found : .+\n.+/m raise ArgumentError, "Selenium < 3.14 with remote Chrome doesn't support multiple file upload" end raise end def drag_to(element) return super unless self[:draggable] == 'true' scroll_if_needed { browser_action.click_and_hold(native).perform } driver.execute_script HTML5_DRAG_DROP_SCRIPT, self, element end private def bridge driver.browser.send(:bridge) end HTML5_DRAG_DROP_SCRIPT = <<~JS var source = arguments[0]; var target = arguments[1]; var dt = new DataTransfer(); var opts = { cancelable: true, bubbles: true, dataTransfer: dt }; var dragEvent = new DragEvent('dragstart', opts); source.dispatchEvent(dragEvent); target.scrollIntoView({behavior: 'instant', block: 'center', inline: 'center'}); var dragOverEvent = new DragEvent('dragover', opts); target.dispatchEvent(dragOverEvent); var dragLeaveEvent = new DragEvent('dragleave', opts); target.dispatchEvent(dragLeaveEvent); if (dragOverEvent.defaultPrevented) { var dropEvent = new DragEvent('drop', opts); target.dispatchEvent(dropEvent); } var dragEndEvent = new DragEvent('dragend', opts); source.dispatchEvent(dragEndEvent); JS end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
capybara-3.7.1 | lib/capybara/selenium/nodes/chrome_node.rb |
capybara-3.7.0 | lib/capybara/selenium/nodes/chrome_node.rb |