79500792

Date: 2025-03-11 12:48:47
Score: 0.5
Natty:
Report link

Here's a tweak for @Motine's excellent answer, because I discovered that it no longer worked after updating to selenium-webdriver 4.26. For 4.26 (and presumably later versions, though I haven't tested it!):

module Capybara::Node::Actions
  alias_method :original_attach_file, :attach_file

  def attach_file(*args, **kwargs)
    implement_hacky_fix_for_file_uploads_with_chromedriver
    original_attach_file(*args, **kwargs)
  end

  def implement_hacky_fix_for_file_uploads_with_chromedriver
    return if @hacky_fix_implemented
    Capybara.current_session
    capybara_selenium_driver = session.driver
    selenium_webdriver = capybara_selenium_driver.browser
    bridge = selenium_webdriver.send(:bridge)
    bridge.add_commands({upload_file: [:post, "session/:session_id/file"]})
    @hacky_fix_implemented = true
  end
end
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Motine's
  • Low reputation (0.5):
Posted by: Michael Smart