mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Emulate click on file input when attaching file using Selenium with Chrome and Firefox
This commit is contained in:
parent
2e052792a5
commit
ea6486b328
7 changed files with 40 additions and 5 deletions
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Capybara::Selenium::Node
|
||||
module FileInputClickEmulation
|
||||
private
|
||||
|
||||
def visible_file_field?
|
||||
(attrs(:tagName, :type).map { |val| val&.downcase } == %w[input file]) && visible?
|
||||
end
|
||||
|
||||
def attaching_file?
|
||||
caller_locations.any? { |cl| cl.base_label == 'attach_file' }
|
||||
end
|
||||
|
||||
def emulate_click
|
||||
driver.execute_script(<<~JS, self)
|
||||
arguments[0].dispatchEvent(
|
||||
new MouseEvent('click', {
|
||||
view: window,
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
}));
|
||||
JS
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue