2

How can i clear the contents of an input field using ruby selenium?

i.e when page loads up there are values in the input filed but i want to replace them with new ones.

thank you

Mo.
  • 40,243
  • 37
  • 86
  • 131
  • 1
    See also http://stackoverflow.com/questions/7732125/clear-text-from-textarea-with-selenium for another answer (using .clear()) – bryn Jan 25 '13 at 10:41

2 Answers2

6

Come on guys... You can't be serious...

With selenium to clear an input field do this: selenium.type("") in ruby too.

And backspacing as many times as there are letters... Come on.. you don't do stuff like that.

Or in Ruby syntax: @browser.type "idofthefield", ""

Hannibal
  • 1,078
  • 2
  • 12
  • 24
  • 2
    thanks, I thought that selenium.type("") would just add nothing to the input already there. thanks – Mo. Sep 17 '10 at 09:49
  • 2
    The proper function is called `clear()`. You can't be serious ... readthedocs please. – m3nda Oct 21 '18 at 01:23
1

This is how i cleared and replaced with new text in my Ruby based web portal test

@driver.find_element(:xpath, "//input[@name='ip-address']").clear
@driver.find_element(:xpath, "//input[@name='ip-address']").send_keys(new_ip_address)
Nafeez Quraishi
  • 5,380
  • 2
  • 27
  • 34
  • This is the way to "clear" a field. Im glad you use .clear with no () function call ... – m3nda Oct 21 '18 at 01:22