Class: Puppeteer::Dialog

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/dialog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, type:, message:, default_value:) ⇒ Dialog

Returns a new instance of Dialog.



2
3
4
5
6
7
# File 'lib/puppeteer/dialog.rb', line 2

def initialize(client, type:, message:, default_value:)
  @client = client
  @type = type
  @message = message
  @default_value = default_value || ''
end

Instance Attribute Details

#default_valueObject (readonly)

Returns the value of attribute default_value.



9
10
11
# File 'lib/puppeteer/dialog.rb', line 9

def default_value
  @default_value
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/puppeteer/dialog.rb', line 9

def message
  @message
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/puppeteer/dialog.rb', line 9

def type
  @type
end

Instance Method Details

#accept(prompt_text = nil) ⇒ Object

prompt. Has no effect if the dialog’s type is not ‘prompt`.

Parameters:

  • prompt_text (defaults to: nil)
    • optional text that will be entered in the dialog



15
16
17
18
19
20
21
22
23
24
# File 'lib/puppeteer/dialog.rb', line 15

def accept(prompt_text = nil)
  if @handled
    raise 'Cannot accept dialog which is already handled!'
  end
  @handled = true
  @client.send_message('Page.handleJavaScriptDialog', {
    accept: true,
    promptText: prompt_text,
  }.compact)
end

#dismissObject



27
28
29
30
31
32
33
# File 'lib/puppeteer/dialog.rb', line 27

def dismiss
  if @handled
    raise 'Cannot accept dialog which is already handled!'
  end
  @handled = true
  @client.send_message('Page.handleJavaScriptDialog', accept: false)
end