question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.clear() seems not clearing when the cursor is in front of the text

See original GitHub issue

Hi there! I’m not sure if this a bug or intended, please confirm it.

  • Node Version: 8.11.1
  • Protractor Version: 5.1.2
  • Angular Version: 5.1.0
  • Browser(s): Chrome
  • Operating System and Version macOS 10.13.2

In my case, I have a html input element with its cursor in front of the text. I’m able to do sendKeys() with no problems, but clear() seems not clearing anything. If I do the same thing with other input elements whose cursors are in the end of their text, everything works fine. My code sample is something like this:

 this.zip = element(by.id('zip')).element(by.css('input'));
 await this.zip.clear();
 await this.zip.sendKeys(input);

this.zip is the input element with cursor in front of its text And I also notice if I do a click() before clear(). It does clear the text, but sendKeys(input) would put text back.

 await this.zip.click();
//browser.sleep(2000);
 await this.zip.clear();
//browser.sleep(2000);
 await this.zip.sendKeys(input);

so for example: if the original text in zip is 12345, and input is 6789, after the above execution, it would show 678912345. I put browser.sleep(2000) in between each method and I can see in the browser, it clear the zip field, and when it does sendKeys(input), it puts 6789 in, but for some reason, 12345 comes back. From what I understanding, the clear() function should clear the text regardless of the cursor position. Can someone explain the trick behind it?

EDIT: One thing I forgot to mention, the input element zip is a sub-element of p-inputmask, which is from PRIMENG. Here is what it looks like in Chrome.

<p-inputmask id="zip" mask="?99999-9999999999999" unmask="true" ng-reflect-disabled="false" ng-reflect-unmask="true" ng-reflect-mask="?99999-9999999999999" ng-reflect-is-disabled="false" class="ng-valid ui-inputwrapper-filled ng-touched ng-dirty" ng-reflect-model="928359283592835928">
    <input pinputtext type="text" class="ui-inputtext ui-corner-all ui-state-default ui-widget ui-state-filled">
</p-inputmask>

Thanks

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

1reaction
Tandy1234commented, Apr 27, 2018

@awarecan I modified that a little bit and now it seems working.

    this.mask = element(by.id('zip));
    this.zip = element(by.id('zip')).element(by.css('input'));
    await this.mask.click();
    await this.zip.sendKeys(Key.SHIFT, Key.END, Key.BACK_SPACE);
    await this.zip.sendKeys(input);

Thanks you much

1reaction
awarecancommented, Apr 27, 2018

Since you have a such powerful inputmask element on above your input, I would suggest you interactive with inputmask instead input.

this.zip = element(by.id('zip'));
await this.zip.click();
await this.zip.sendKeys(Key.SHIFT, Key.END, Key.BACK_SPACE);
await this.zip.sendKeys(input);
Read more comments on GitHub >

github_iconTop Results From Across the Web

My text cursor keeps going to the left side and I can't click on
My laptop suddenly won't type properly and the text cursor keeps going to the left most or right most when typing in some...
Read more >
How to reset cursor to the beginning of the same line in Python
How to reset cursor to the beginning of the same line in Python · 1. Can you output ASCII character 8 (a backspace)...
Read more >
Delete the word in which the text cursor is - Super User
Ctrl + Backspace deletes the current word up until the text cursor. Ctrl + Del deletes the end of the current word from...
Read more >
Keyboard Shortcuts (Windows)
Selects lines of text ... Selects and cycles forward through objects (if cursor ... Delete. Clear contents of selection. Ctrl + Z. Undo...
Read more >
Qwerty keys - University of Bristol
Used to delete one character at a time to the left of the cursor. You can also click and drag to highlight text...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found