Method: Selenium::WebDriver::Driver#type

Defined in:
lib/oats/oats_selenium_api.rb

#type(locator, value, retype = false, delay = false) ⇒ Object Also known as: key_press

Complete the text in locator to value if necessary and return locator If webdriver, set retype to true if you want to clear the input and retype. If you just want to type value without clearing the element, set retype=>nil.



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
353
354
355
356
357
358
# File 'lib/oats/oats_selenium_api.rb', line 321

def type(locator, value, retype = false, delay = false)
  value = value.to_s
  #      if webdriver?
  locator = element?(locator)
  el = locator.element
  if retype
    xtra = value
    locator.element.clear
  else
    old = el[:value]
    xtra = value.sub(/^#{old}/,'')
    el.clear if xtra == value and old != '' and !retype.nil?
  end
  if xtra == ''
    if old == ''
      oats_debug "type skipping already existing '#{value}' at #{locator}"
    elsif xtra == value
      oats_debug "type cleared already existing '#{old}' at #{locator}"
    end
  else
    oats_debug "type '#{xtra}' at #{locator}"
    if delay
      xtra = xtra.split(//)
      for i in 0..xtra.length
#          selenium.sleep 1
        el.send_keys(xtra[i])
      end
    else
      el.send_keys(xtra)
    end
  end
  #      else
  #        locator ||= @last_locator
  #        oats_debug "type '#{value}' at #{locator}"
  #        type_orig(locator, value)
  #      end
  return locator
end