Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form.fill() doesn't clear text inputs before calling sendKeys() #65

Closed
alkedr opened this issue Jul 22, 2014 · 5 comments
Closed

Form.fill() doesn't clear text inputs before calling sendKeys() #65

alkedr opened this issue Jul 22, 2014 · 5 comments

Comments

@alkedr
Copy link
Contributor

alkedr commented Jul 22, 2014

If input with type 'text' or 'password' already has value Form.fill() will append to it, not replace.

Form.java, lines 71-73

if (inputType == null || inputType.equals(TEXT_INPUT_TYPE) || inputType.equals(PASSWORD_INPUT_TYPE)) {
    // add element.clear(); here
    element.sendKeys(value.toString());
}
@aik099
Copy link
Contributor

aik099 commented Jul 22, 2014

Yes, because the sendKeys only types keys and doesn't clear input value.

I'd suggest taking an approach of sending N number of backspace symbols (N is number of symbols currently in that field) and then actual new string. Beware that you need to send both BACKSPACE (for Windows/Linux) and DELETE (for Mac) symbols for that to work.

Working example in PHP: https://github.com/Behat/MinkSelenium2Driver/blob/master/src/Behat/Mink/Driver/Selenium2Driver.php#L667

@alkedr
Copy link
Contributor Author

alkedr commented Jul 22, 2014

That's a nice trick, I didn't think of that.
But isn't this a bug and shouldn't it be fixed by adding element.clear(); before sendKeys()?

@aik099
Copy link
Contributor

aik099 commented Jul 22, 2014

If you call .clear() it will clear the element value, however it will also trigger onchange event in JavaScript. So for setting field value you'll get 2 onchange JavaScript event fired (one from clearing previous value and one from setting new one).

Since real user will only get onchange event when he leaves the field, then the backspace/delete solution seems to be more appropriate solution.

@alkedr
Copy link
Contributor Author

alkedr commented Jul 22, 2014

Trick with backspaces is even nicer than I thought! :)
Will it be implemented?

@aik099
Copy link
Contributor

aik099 commented Jul 23, 2014

Trick with backspaces is even nicer than I thought! :) Will it be implemented?

It's up to you I guess. PR are welcome.

By the way in my PHP implementation of HtmlElements I've decided to remove that IF statement by inputType to allow HTML5 elements like <input type="email"/> and other to be fillable as well: https://github.com/qa-tools/qa-tools/blob/master/library/QATools/QATools/HtmlElements/Element/Form.php#L119

artkoshelev added a commit that referenced this issue Aug 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants