Class: Puppeteer::Bidi::FileChooser
- Inherits:
-
Object
- Object
- Puppeteer::Bidi::FileChooser
- Defined in:
- lib/puppeteer/bidi/file_chooser.rb,
sig/puppeteer/bidi/file_chooser.rbs
Overview
FileChooser represents a file chooser dialog opened by an input element Based on Puppeteer's FileChooser implementation
Instance Method Summary collapse
-
#accept(paths) ⇒ Object
Accept the file chooser with the given file paths.
-
#cancel ⇒ Object
Cancel the file chooser.
- #initialize(element, multiple) ⇒ Object constructor
-
#multiple? ⇒ Boolean
Check if multiple files can be selected.
Constructor Details
#initialize(element, multiple) ⇒ Object
11 12 13 14 15 |
# File 'lib/puppeteer/bidi/file_chooser.rb', line 11 def initialize(element, multiple) @element = element @multiple = multiple @handled = false end |
Instance Method Details
#accept(paths) ⇒ Object
Accept the file chooser with the given file paths
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/puppeteer/bidi/file_chooser.rb', line 27 def accept(paths) raise 'Cannot accept FileChooser which is already handled!' if @handled # Validate that single-file inputs don't receive multiple files if !@multiple && paths.length > 1 raise 'Multiple file paths passed to a file input that does not accept multiple files' end @handled = true @element.upload_file(*paths) end |
#cancel ⇒ Object
Cancel the file chooser
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/puppeteer/bidi/file_chooser.rb', line 41 def cancel raise 'Cannot cancel FileChooser which is already handled!' if @handled @handled = true @element.evaluate(<<~JAVASCRIPT) element => { element.dispatchEvent(new Event('cancel', {bubbles: true})); } JAVASCRIPT end |
#multiple? ⇒ Boolean
Check if multiple files can be selected
19 20 21 |
# File 'lib/puppeteer/bidi/file_chooser.rb', line 19 def multiple? @multiple end |