Solution 1 :

I think you are looking for protractor.Key.BACK_SPACE.

element(by.id('textfield_13')).sendKeys(protractor.Key.BACK_SPACE);

Problem :

Hello stackoverflow community!

Problem

I have this piece of HTML code:

<div class="ds-u-clearfix ds-l-col--auto">
    :: before
    <label class="ds-c-label ds-u-font-weight--normal ds-u-margin-top--1" for="textfield_13" id="textfield_label_14">
        <span class="">Day</span>
    </label>
    <input class="ds-c-field ds-c-field--day ds-c-field--error" id="textfield_13" type="number" max="31" min="1" name="day" aria-describedby="datefield_label_10" value="01">
    :: after
</div>

I’m working on test automation using protractor and I need to clear an input field that has a value already. Protractor’s .clear() doesn’t work (literally has no effect). So I though I could inject a script to the devtools’ console to change the value. But when I do that (eg $elem.value = "") it looks like it’s clearing the input, but if I start typing another value, the previous one appears again

Question

How do I clear the value of the input permanently?

What I tried so far

$elem.value = "";
$elem.value = null;
$elem.defaultValue = "";
$elem.setAttribute ("value", "");
// and many more

Again, whenever I do any of this^^ it looks like the input is cleared, but then the value comes back if I start typing

Thanks for reading to the end 🙂

Comments

Comment posted by github.com/angular/protractor/issues/690

Frankly I don’t care how to solve this – from devtools or from protractor itself, so any ideas are appreciated. I was thinking about doing

Comment posted by Shivanshu Gupta

you can use document.getElementById(“textfield_13”).value = “” to clear your input value

Comment posted by Autocomplete off vs false?

Does this answer your question?

Comment posted by Sergey Pleshakov

@ShivanshuGupta if you read the question, you’ll notice I tried that already

Comment posted by Sergey Pleshakov

@Gerard the entire html page has no references to

Comment posted by Sergey Pleshakov

I’ll get back to you in a bit, thanks for the answer @jortega

By