0

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 :)

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40
  • 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 `ctrl + A` and then `Delete`, but that's incompatible with Mac. Mac needs `Command + A`, and looks like command key will never be supported https://github.com/angular/protractor/issues/690 – Sergey Pleshakov Jun 24 '20 at 16:18
  • you can use document.getElementById("textfield_13").value = "" to clear your input value – Shivanshu Gupta Jun 24 '20 at 16:28
  • Does this answer your question? [Autocomplete off vs false?](https://stackoverflow.com/questions/30053167/autocomplete-off-vs-false) – Gerard Jun 24 '20 at 16:31
  • @ShivanshuGupta if you read the question, you'll notice I tried that already – Sergey Pleshakov Jun 24 '20 at 16:49
  • @Gerard the entire html page has no references to `autocomplete` attribute. I even tried to still set `autocomplete="off"` of the `input` itself, and of the `form` it belongs to, and it didn't help, unless I did wrong – Sergey Pleshakov Jun 24 '20 at 16:58

1 Answers1

0

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

element(by.id('textfield_13')).sendKeys(protractor.Key.BACK_SPACE);
Jortega
  • 3,616
  • 1
  • 18
  • 21