How to remove text from textarea using backspace in nightwatch.js

1,802 views
Skip to first unread message

Ashish Jain

unread,
Feb 4, 2016, 4:01:30 AM2/4/16
to NightwatchJs

Hi All,


I am working on nightwatch.js, i want to update existing data so i need to remove old date and need to set new data, i tried two way to get my result.


1) set empty text using following nightwatch function.


browser.setValue('.MyClass', 'text',' ');


2) here i tried to use backspace but unfortunately nightwatch.js api documentation is not so good, so i tried following with the help of this link but not worked.


client.keys([client.Keys.COMMAND, "Backspace", client.Keys.NULL]);


above code not pressed mouse backspace but append 'Backspace'.


If you have any best idea, please let me know. This question has already posted on Stackoverflow, i am sending a link following.


http://stackoverflow.com/questions/35195307/how-to-remove-text-from-textarea-using-backspace-in-nightwatch-js




J Dent

unread,
Mar 29, 2016, 9:56:30 AM3/29/16
to NightwatchJs
have you tried using client.clearValue('#some-element')?
Message has been deleted

Serj grigoryak

unread,
Aug 9, 2016, 11:48:33 AM8/9/16
to NightwatchJs
mb provide some focus on field, like "moveTo" mouse or smth,  and client.sendKeys(''element'' , "BACKSPACE")

Kim Milán

unread,
Aug 12, 2016, 4:39:18 AM8/12/16
to NightwatchJs
Try this custom command:

exports.command = function (browser, selector) {
  browser
    .getValue(selector, function(result){
      for (c in result.value){
        browser.setValue(selector, "\u0008")
      }
    })
  return this;
};

I had problems with .clearValue so clearing the text using backspaces with this command fixed my problem. Basically you send it the selector and it setValues as many backspaces as there are letters/numbers in the value.

It's an ugly solution, but at least for me, it was necessary due to .clearValue screwing up the input field's functionality...
Reply all
Reply to author
Forward
0 new messages