0

I am trying to run selenium webdriver, imitating typing something to textbox and submit it.

I have this following code:

WebElement element = null;
element = waitForElementPresent(tFByCssSelector,timeoutValue);
element.clear();
element.click();
element.sendKeys("Input String");

The code successfully type "Input String" to the textField, but when I submit the form, it says the form is empty (The form had been set to catch empty input exception).

I wonder why sendKeys does not set the value of the text field even though it has typed the wanted value into the text field.

2 Answers 2

2

Try to tab out of the field:

element.sendKeys("Input String");
element.sendKeys(Keys.TAB);

It may be that the field value only gets set on blur.

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

1 Comment

Thanks. I did similar action. I typed and then clear it, then resend again. It works. Seems this only happened in FF. In Chrome it works well without this workaround.
0

As I see, all looks okay in your selenium code. I believe there is some problem with your HTML form.

The form should have proper action for receiving the values. A sample form is provided below.

<form action="http://foo.com" method="post">
  <input name="say" value="Hi">
  <input name="to" value="Mom">
  <button>Send my greetings</button>
</form>

Based on what you use in method parameter, you will get the form data in POST or GET variables.

Also you don't need to click on the element before sending keys in Selenium.

1 Comment

Thanks for the answer. However, when I type manually, it succeed. So I dont think there is anything wrong with my form.

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.