Class: Capybara::Playwright::Node::TextInput

Inherits:
Settable
  • Object
show all
Defined in:
lib/capybara/playwright/node.rb

Instance Method Summary collapse

Methods inherited from Settable

#initialize

Constructor Details

This class inherits a constructor from Capybara::Playwright::Node::Settable

Instance Method Details

#set(value, **options) ⇒ Object



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/capybara/playwright/node.rb', line 401

def set(value, **options)
  case options[:clear]
  when :backspace
    @element.press('End', timeout: @timeout)
    existing_text = @element.evaluate('el => el.value')
    existing_text.length.times { @element.press('Backspace', timeout: @timeout) }
  when :none
    @element.press('End', timeout: @timeout)
  when Array
    @internal_logger.warn "options { clear: #{options[:clear]} } is ignored"
  end

  text = value.to_s
  if press_enter = text.end_with?("\r\n")
    text = text[0...-2]
  elsif press_enter = text.end_with?("\n")
    text = text[0...-1]
  end

  set_text(text, append: options[:clear] == :none)

  if press_enter
    @element.press('Enter', timeout: @timeout)
  end
rescue ::Playwright::TimeoutError
  raise if @element.editable?

  @internal_logger.info("Node#set: element is not editable. #{@element}")
end