Class: Playwright::ChannelOwners::ElementHandle

Inherits:
JSHandle show all
Defined in:
lib/playwright/channel_owners/element_handle.rb

Instance Method Summary collapse

Methods inherited from JSHandle

#dispose, #evaluate, #evaluate_handle, #get_properties, #get_property, #json_value, #off, #on, #once, #to_s

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#as_elementObject



12
13
14
# File 'lib/playwright/channel_owners/element_handle.rb', line 12

def as_element
  self
end

#bounding_boxObject



311
312
313
# File 'lib/playwright/channel_owners/element_handle.rb', line 311

def bounding_box
  @channel.send_message_to_server('boundingBox')
end

#check(force: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/playwright/channel_owners/element_handle.rb', line 275

def check(force: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil)
  params = {
    force: force,
    noWaitAfter:  noWaitAfter,
    position: position,
    scroll: scroll,
    timeout: _timeout(timeout),
    trial: trial,
  }.compact
  @channel.send_message_to_server('check', params)

  nil
end

#checked?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/playwright/channel_owners/element_handle.rb', line 42

def checked?
  @channel.send_message_to_server('isChecked')
end

#click(button: nil, clickCount: nil, delay: nil, force: nil, modifiers: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil, steps: nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/playwright/channel_owners/element_handle.rb', line 107

def click(
      button: nil,
      clickCount: nil,
      delay: nil,
      force: nil,
      modifiers: nil,
      noWaitAfter: nil,
      position: nil,
      scroll: nil,
      timeout: nil,
      trial: nil,
      steps: nil)

  params = {
    button: button,
    clickCount: clickCount,
    delay: delay,
    force: force,
    modifiers: modifiers,
    noWaitAfter: noWaitAfter,
    position: position,
    scroll: scroll,
    timeout: _timeout(timeout),
    trial: trial,
    steps: steps,
  }.compact
  @channel.send_message_to_server('click', params)

  nil
end

#content_frameObject



21
22
23
24
# File 'lib/playwright/channel_owners/element_handle.rb', line 21

def content_frame
  resp = @channel.send_message_to_server('contentFrame')
  ChannelOwners::Frame.from_nullable(resp)
end

#dblclick(button: nil, delay: nil, force: nil, modifiers: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil, steps: nil) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/playwright/channel_owners/element_handle.rb', line 138

def dblclick(
      button: nil,
      delay: nil,
      force: nil,
      modifiers: nil,
      noWaitAfter: nil,
      position: nil,
      scroll: nil,
      timeout: nil,
      trial: nil,
      steps: nil)

  params = {
    button: button,
    delay: delay,
    force: force,
    modifiers: modifiers,
    noWaitAfter: noWaitAfter,
    position: position,
    scroll: scroll,
    timeout: _timeout(timeout),
    trial: trial,
    steps: steps,
  }.compact
  @channel.send_message_to_server('dblclick', params)

  nil
end

#disabled?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/playwright/channel_owners/element_handle.rb', line 46

def disabled?
  @channel.send_message_to_server('isDisabled')
end

#dispatch_event(type, eventInit: nil) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/playwright/channel_owners/element_handle.rb', line 66

def dispatch_event(type, eventInit: nil)
  params = {
    type: type,
    eventInit: JavaScript::ValueSerializer.new(eventInit).serialize,
  }.compact
  @channel.send_message_to_server('dispatchEvent', params)

  nil
end

#editable?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/playwright/channel_owners/element_handle.rb', line 50

def editable?
  @channel.send_message_to_server('isEditable')
end

#enabled?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/playwright/channel_owners/element_handle.rb', line 54

def enabled?
  @channel.send_message_to_server('isEnabled')
end

#eval_on_selector(selector, pageFunction, arg: nil) ⇒ Object



365
366
367
# File 'lib/playwright/channel_owners/element_handle.rb', line 365

def eval_on_selector(selector, pageFunction, arg: nil)
  JavaScript::Expression.new(pageFunction, arg).eval_on_selector(@channel, selector)
end

#eval_on_selector_all(selector, pageFunction, arg: nil) ⇒ Object



369
370
371
# File 'lib/playwright/channel_owners/element_handle.rb', line 369

def eval_on_selector_all(selector, pageFunction, arg: nil)
  JavaScript::Expression.new(pageFunction, arg).eval_on_selector_all(@channel, selector)
end

#fill(value, force: nil, noWaitAfter: nil, timeout: nil) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
# File 'lib/playwright/channel_owners/element_handle.rb', line 208

def fill(value, force: nil, noWaitAfter: nil, timeout: nil)
  params = {
    value: value,
    force: force,
    noWaitAfter: noWaitAfter,
    timeout: _timeout(timeout),
  }.compact
  @channel.send_message_to_server('fill', params)

  nil
end

#focusObject



245
246
247
248
249
# File 'lib/playwright/channel_owners/element_handle.rb', line 245

def focus
  @channel.send_message_to_server('focus')

  nil
end

#get_attribute(name) ⇒ Object



26
27
28
# File 'lib/playwright/channel_owners/element_handle.rb', line 26

def get_attribute(name)
  @channel.send_message_to_server('getAttribute', name: name)
end

#hidden?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/playwright/channel_owners/element_handle.rb', line 58

def hidden?
  @channel.send_message_to_server('isHidden')
end

#hover(force: nil, modifiers: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/playwright/channel_owners/element_handle.rb', line 85

def hover(
      force: nil,
      modifiers: nil,
      noWaitAfter: nil,
      position: nil,
      scroll: nil,
      timeout: nil,
      trial: nil)
  params = {
    force: force,
    modifiers: modifiers,
    noWaitAfter: noWaitAfter,
    position: position,
    scroll: scroll,
    timeout: _timeout(timeout),
    trial: trial,
  }.compact
  @channel.send_message_to_server('hover', params)

  nil
end

#inner_htmlObject



38
39
40
# File 'lib/playwright/channel_owners/element_handle.rb', line 38

def inner_html
  @channel.send_message_to_server('innerHTML')
end

#inner_textObject



34
35
36
# File 'lib/playwright/channel_owners/element_handle.rb', line 34

def inner_text
  @channel.send_message_to_server('innerText')
end

#input_value(timeout: nil) ⇒ Object



227
228
229
230
# File 'lib/playwright/channel_owners/element_handle.rb', line 227

def input_value(timeout: nil)
  params = { timeout: _timeout(timeout) }.compact
  @channel.send_message_to_server('inputValue', params)
end

#owner_frameObject



16
17
18
19
# File 'lib/playwright/channel_owners/element_handle.rb', line 16

def owner_frame
  resp = @channel.send_message_to_server('ownerFrame')
  ChannelOwners::Frame.from_nullable(resp)
end

#press(key, delay: nil, noWaitAfter: nil, timeout: nil) ⇒ Object



263
264
265
266
267
268
269
270
271
272
273
# File 'lib/playwright/channel_owners/element_handle.rb', line 263

def press(key, delay: nil, noWaitAfter: nil, timeout: nil)
  params = {
    key: key,
    delay: delay,
    noWaitAfter: noWaitAfter,
    timeout: _timeout(timeout),
  }.compact
  @channel.send_message_to_server('press', params)

  nil
end

#query_selector(selector) ⇒ Object



354
355
356
357
# File 'lib/playwright/channel_owners/element_handle.rb', line 354

def query_selector(selector)
  resp = @channel.send_message_to_server('querySelector', selector: selector)
  ChannelOwners::ElementHandle.from_nullable(resp)
end

#query_selector_all(selector) ⇒ Object



359
360
361
362
363
# File 'lib/playwright/channel_owners/element_handle.rb', line 359

def query_selector_all(selector)
  @channel.send_message_to_server('querySelectorAll', selector: selector).map do |el|
    ChannelOwners::ElementHandle.from(el)
  end
end

#screenshot(animations: nil, caret: nil, mask: nil, maskColor: nil, omitBackground: nil, path: nil, quality: nil, scale: nil, style: nil, timeout: nil, type: nil) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/playwright/channel_owners/element_handle.rb', line 315

def screenshot(
  animations: nil,
  caret: nil,
  mask: nil,
  maskColor: nil,
  omitBackground: nil,
  path: nil,
  quality: nil,
  scale: nil,
  style: nil,
  timeout: nil,
  type: nil)

  params = {
    animations: animations,
    caret: caret,
    maskColor: maskColor,
    omitBackground: omitBackground,
    quality: quality,
    scale: scale,
    style: style,
    timeout: _timeout(timeout),
    type: ScreenshotUtils.determine_type(path: path, type: type),
  }.compact
  if mask.is_a?(Enumerable)
    params[:mask] = mask.map do |locator|
      locator.send(:to_protocol)
    end
  end
  encoded_binary = @channel.send_message_to_server('screenshot', params)
  decoded_binary = Base64.strict_decode64(encoded_binary)
  if path
    File.open(path, 'wb') do |f|
      f.write(decoded_binary)
    end
  end
  decoded_binary
end

#scroll_into_view_if_needed(timeout: nil) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/playwright/channel_owners/element_handle.rb', line 76

def scroll_into_view_if_needed(timeout: nil)
  params = {
    timeout: _timeout(timeout),
  }.compact
  @channel.send_message_to_server('scrollIntoViewIfNeeded', params)

  nil
end

#select_option(element: nil, index: nil, value: nil, label: nil, force: nil, noWaitAfter: nil, timeout: nil) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/playwright/channel_owners/element_handle.rb', line 167

def select_option(
      element: nil,
      index: nil,
      value: nil,
      label: nil,
      force: nil,
      noWaitAfter: nil,
      timeout: nil)
  base_params = SelectOptionValues.new(
    element: element,
    index: index,
    value: value,
    label: label,
  ).as_params
  params = base_params.merge({ force: force, noWaitAfter: noWaitAfter, timeout: _timeout(timeout) }.compact)
  @channel.send_message_to_server('selectOption', params)
end

#select_text(force: nil, timeout: nil) ⇒ Object



220
221
222
223
224
225
# File 'lib/playwright/channel_owners/element_handle.rb', line 220

def select_text(force: nil, timeout: nil)
  params = { force: force, timeout: _timeout(timeout) }.compact
  @channel.send_message_to_server('selectText', params)

  nil
end

#set_checked(checked, **options) ⇒ Object



303
304
305
306
307
308
309
# File 'lib/playwright/channel_owners/element_handle.rb', line 303

def set_checked(checked, **options)
  if checked
    check(**options)
  else
    uncheck(**options)
  end
end

#set_input_files(files, noWaitAfter: nil, timeout: nil) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/playwright/channel_owners/element_handle.rb', line 232

def set_input_files(files, noWaitAfter: nil, timeout: nil)
  frame = owner_frame
  unless frame
    raise 'Cannot set input files to detached element'
  end

  method_name, params = InputFiles.new(frame.page.context, files).as_method_and_params
  params.merge!({ noWaitAfter: noWaitAfter, timeout: _timeout(timeout) }.compact)
  @channel.send_message_to_server(method_name, params)

  nil
end

#tap_point(force: nil, modifiers: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/playwright/channel_owners/element_handle.rb', line 185

def tap_point(
      force: nil,
      modifiers: nil,
      noWaitAfter: nil,
      position: nil,
      scroll: nil,
      timeout: nil,
      trial: nil)

  params = {
    force: force,
    modifiers: modifiers,
    noWaitAfter: noWaitAfter,
    position: position,
    scroll: scroll,
    timeout: _timeout(timeout),
    trial: trial,
  }.compact
  @channel.send_message_to_server('tap', params)

  nil
end

#text_contentObject



30
31
32
# File 'lib/playwright/channel_owners/element_handle.rb', line 30

def text_content
  @channel.send_message_to_server('textContent')
end

#type(text, delay: nil, noWaitAfter: nil, timeout: nil) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
# File 'lib/playwright/channel_owners/element_handle.rb', line 251

def type(text, delay: nil, noWaitAfter: nil, timeout: nil)
  params = {
    text: text,
    delay: delay,
    noWaitAfter: noWaitAfter,
    timeout: _timeout(timeout),
  }.compact
  @channel.send_message_to_server('type', params)

  nil
end

#uncheck(force: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil) ⇒ Object



289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/playwright/channel_owners/element_handle.rb', line 289

def uncheck(force: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil)
  params = {
    force: force,
    noWaitAfter:  noWaitAfter,
    position: position,
    scroll: scroll,
    timeout: _timeout(timeout),
    trial: trial,
  }.compact
  @channel.send_message_to_server('uncheck', params)

  nil
end

#visible?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/playwright/channel_owners/element_handle.rb', line 62

def visible?
  @channel.send_message_to_server('isVisible')
end

#wait_for_element_state(state, timeout: nil) ⇒ Object



373
374
375
376
377
378
# File 'lib/playwright/channel_owners/element_handle.rb', line 373

def wait_for_element_state(state, timeout: nil)
  params = { state: state, timeout: _timeout(timeout) }.compact
  @channel.send_message_to_server('waitForElementState', params)

  nil
end

#wait_for_selector(selector, state: nil, strict: nil, timeout: nil) ⇒ Object



380
381
382
383
384
385
# File 'lib/playwright/channel_owners/element_handle.rb', line 380

def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
  params = { selector: selector, state: state, strict: strict, timeout: _timeout(timeout) }.compact
  resp = @channel.send_message_to_server('waitForSelector', params)

  ChannelOwners::ElementHandle.from_nullable(resp)
end