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

1

2 Answers 2

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", ""

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, I thought that selenium.type("") would just add nothing to the input already there. thanks
The proper function is called clear(). You can't be serious ... readthedocs please.
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)

1 Comment

This is the way to "clear" a field. Im glad you use .clear with no () function call ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.