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

Methods inherited from PlaywrightApi

#==, #initialize, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#as_elementObject



6
7
8
# File 'lib/playwright/channel_owners/element_handle.rb', line 6

def as_element
  self
end

#bounding_boxObject



255
256
257
# File 'lib/playwright/channel_owners/element_handle.rb', line 255

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

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



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

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

  nil
end

#checked?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/playwright/channel_owners/element_handle.rb', line 36

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

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



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/playwright/channel_owners/element_handle.rb', line 91

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

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

  nil
end

#content_frameObject



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

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, timeout: nil) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/playwright/channel_owners/element_handle.rb', line 116

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

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

  nil
end

#disabled?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/playwright/channel_owners/element_handle.rb', line 40

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

#dispatch_event(type, eventInit: nil) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/playwright/channel_owners/element_handle.rb', line 60

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)


44
45
46
# File 'lib/playwright/channel_owners/element_handle.rb', line 44

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

#enabled?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/playwright/channel_owners/element_handle.rb', line 48

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

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



294
295
296
297
298
299
300
# File 'lib/playwright/channel_owners/element_handle.rb', line 294

def eval_on_selector(selector, pageFunction, arg: nil)
  if JavaScript.function?(pageFunction)
    JavaScript::Function.new(pageFunction, arg).eval_on_selector(@channel, selector)
  else
    JavaScript::Expression.new(pageFunction).eval_on_selector(@channel, selector)
  end
end

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



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

def eval_on_selector_all(selector, pageFunction, arg: nil)
  if JavaScript.function?(pageFunction)
    JavaScript::Function.new(pageFunction, arg).eval_on_selector_all(@channel, selector)
  else
    JavaScript::Expression.new(pageFunction).eval_on_selector_all(@channel, selector)
  end
end

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



177
178
179
180
181
182
183
184
185
186
# File 'lib/playwright/channel_owners/element_handle.rb', line 177

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

  nil
end

#focusObject



203
204
205
206
207
# File 'lib/playwright/channel_owners/element_handle.rb', line 203

def focus
  @channel.send_message_to_server('focus')

  nil
end

#get_attribute(name) ⇒ Object



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

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

#hidden?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/playwright/channel_owners/element_handle.rb', line 52

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

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



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/playwright/channel_owners/element_handle.rb', line 79

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

  nil
end

#inner_htmlObject



32
33
34
# File 'lib/playwright/channel_owners/element_handle.rb', line 32

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

#inner_textObject



28
29
30
# File 'lib/playwright/channel_owners/element_handle.rb', line 28

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

#owner_frameObject



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

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



221
222
223
224
225
226
227
228
229
230
231
# File 'lib/playwright/channel_owners/element_handle.rb', line 221

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

  nil
end

#query_selector(selector) ⇒ Object



283
284
285
286
# File 'lib/playwright/channel_owners/element_handle.rb', line 283

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

#query_selector_all(selector) ⇒ Object



288
289
290
291
292
# File 'lib/playwright/channel_owners/element_handle.rb', line 288

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

#screenshot(omitBackground: nil, path: nil, quality: nil, timeout: nil, type: nil) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/playwright/channel_owners/element_handle.rb', line 259

def screenshot(
  omitBackground: nil,
  path: nil,
  quality: nil,
  timeout: nil,
  type: nil)

  params = {
    omitBackground: omitBackground,
    path: path,
    quality: quality,
    timeout: timeout,
    type: type,
  }.compact
  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



70
71
72
73
74
75
76
77
# File 'lib/playwright/channel_owners/element_handle.rb', line 70

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

  nil
end

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



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/playwright/channel_owners/element_handle.rb', line 139

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

  nil
end

#select_text(timeout: nil) ⇒ Object



188
189
190
191
192
193
# File 'lib/playwright/channel_owners/element_handle.rb', line 188

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

  nil
end

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



195
196
197
198
199
200
201
# File 'lib/playwright/channel_owners/element_handle.rb', line 195

def set_input_files(files, noWaitAfter: nil, timeout: nil)
  file_payloads = InputFiles.new(files).as_params
  params = { files: file_payloads, noWaitAfter: noWaitAfter, timeout: timeout }.compact
  @channel.send_message_to_server('setInputFiles', params)

  nil
end

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



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/playwright/channel_owners/element_handle.rb', line 158

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

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

  nil
end

#text_contentObject



24
25
26
# File 'lib/playwright/channel_owners/element_handle.rb', line 24

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

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



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

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

  nil
end

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



244
245
246
247
248
249
250
251
252
253
# File 'lib/playwright/channel_owners/element_handle.rb', line 244

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

  nil
end

#visible?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/playwright/channel_owners/element_handle.rb', line 56

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

#wait_for_element_state(state, timeout: nil) ⇒ Object



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

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

  nil
end

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



317
318
319
320
321
322
# File 'lib/playwright/channel_owners/element_handle.rb', line 317

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

  ChannelOwners::ElementHandle.from_nullable(resp)
end