Nightwatch: clearValue is not working with chromedriver 2.44

Created on 3 Dec 2018  路  8Comments  路  Source: nightwatchjs/nightwatch

I got the iusse with .clearValue command on input element. There is no error. It just doesn't clean input.

Chunk of code:

 editSupplier(supplier) {
    return this
        .waitForElementVisible('@city', delay)
        .clearValue('@city')
        .setValue('@city', supplier.city)

        .waitForElementVisible('@supplierAddress', delay)
        .clearValue('@supplierAddress')
        .setValue('@supplierAddress', supplier.address)

        .waitForElementVisible('@postcode', delay)
        .clearValue('@postcode')
        .setValue('@postcode', supplier.postcode)

        .waitForElementVisible('@accountNumber', delay)
        .clearValue('@accountNumber')
        .setValue('@accountNumber', supplier.accountNumber)

        .waitForElementVisible('@phoneNumber', delay)
        .clearValue('@phoneNumber')
        .setValue('@phoneNumber', supplier.phoneNumber)
}

Most helpful comment

Hi, we also recognized the problem with clearValue which does not work properly since we are running our tests with Chrome 71. I updated to the latest Nightwatch version and chromedriver but the problem is still there and not fixed!

After some investigation I found the following Selenium Issue, which looks like to be the reason of this problem: https://github.com/SeleniumHQ/selenium/issues/6741 Unfortunately there are only some ugly workarounds.

@beatfactor could you reopen the issue please?

All 8 comments

Please mention Nightwatch version, Node.js version, OS version and Selenium version (including any driver version if applicable) and in your case, the Chrome Version

Windows 10 Pro v.1803,
Wersja 70.0.3538.110 (Oficjalna wersja) (64-bitowa) [Version 70.0.3538.110 (Official version) (64-bit)],
"nightwatch": "0.9.20",
"selenium-server": "^3.141.59",
"chromedriver": "2.44",

We're only addressing critical issues in v0.9. Please try to upgrade to v1.0 (currently in beta), as this might have been fixed.

Hi, we also recognized the problem with clearValue which does not work properly since we are running our tests with Chrome 71. I updated to the latest Nightwatch version and chromedriver but the problem is still there and not fixed!

After some investigation I found the following Selenium Issue, which looks like to be the reason of this problem: https://github.com/SeleniumHQ/selenium/issues/6741 Unfortunately there are only some ugly workarounds.

@beatfactor could you reopen the issue please?

As a workaround for now, we use this custom function to clear the value. It calculates the length of the value of the element, then sends that many Backspace keys.

const {client} = require('nightwatch-api');
const keys = require('../constants/keys');

const command = function(locator) {
  client.waitForElementVisible(locator);
  client.click(locator);
  client.getValue(locator, function(result) {
    const length = result.value.length;
    console.log(`Clearing element [@${locator.name}] value [${result.value}] by sending ${length} Backspace keys.`);
    for (let i = 0; i < length; i++) {
      client.keys([keys.BACK_SPACE]);
    }
  });
  return this;
};

module.exports.command = command;

while the above is working for me in chrome as a workaround, I get an error in firefox with the above code.

firefox Error while running .sendKeys() protocol action: An unknown error has occurred.

I am using the .keys function and not the .sendKeys function to be clear so I'm thinking that sendKeys must be used under the hood. Any ideas? I'm seeing quite a few people complaining about the use of sendKeys with the geckodriver and selenium but they're all fairly old so I'm not sure if these posts I'm seeing are still relevant.

@Spacarar not sure. we only use chromedriver on our project so I can't speak to geckodriver.

Hello All,
If clearValue method is not working (Known issue of Selenium lib), Then try to add the Unicode Character 'BACKSPACE' to delete existing value in the textbox. See the example,

setValue('@city', ['\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008'])
// find the length of the textbox value and add "\u0008" that many time.
// For Example: If your city name is Chennai, Then you have to add 7 times.(As shown above)

Try this and put your comment.

Was this page helpful?
0 / 5 - 0 ratings