Nightwatch: clearValue is not clearing input type=password field

Created on 21 Sep 2017  路  12Comments  路  Source: nightwatchjs/nightwatch

Hi, I just checked issues and there is no any resolutions to similar issues.

My problem is following, I have emails and password field, the code is:

.clearValue('#email')
.setValue('#email', loginUser.email)
.clearValue('#password')
.setValue('#password', loginUser.password)

But what I have is that email field is got cleared and new value inserted, but for password field it just appends value and not clearing default one.

stale

Most helpful comment

I use a function to get a working "clearValue"

/**
 * A better `clearValue` for inputs having a more complex interaction.
 *
 * @export
 * @param {string} selector
 * @returns
 */

exports.command = function clearValue2 (selector) {
  const { RIGHT_ARROW, BACK_SPACE } = this.Keys
  return this.getValue(selector, (result) => {
    const chars = result.value.split('')
    // Make sure we are at the end of the input
    chars.forEach(() => this.setValue(selector, RIGHT_ARROW))
    // Delete all the existing characters
    chars.forEach(() => this.setValue(selector, BACK_SPACE))
  })
}

All 12 comments

Never had those issues and actually still wondering why so many else facing this.
Afaik you can come around this by .setValue('#email', '');.
regards

@davidlinse setValue does not remove current value in the field, that's actually very inconvenient as you need to use clearValue every time.

if you set value before clear it and re-set it again it will work
do this:

.clearValue('#email')
.setValue('#email', loginUser.email)

.setValue('#password', loginUser.password)
.clearValue('#password')
.setValue('#password', loginUser.password)

@farhadf246 thanks a lot it worked fine 馃榾馃榾

Seems to not working anymore (since a chromedriver update)? :(

Is this working again? I get connection refused errors from java.

not working also, any update?

Current NW version: ^1.0.18
Chromedriver : ChromeDriver 2.46.628402


Found a work around from #701 thanks to @minyanghbc

.setValue('input[type=password]', '[email protected]')

to clear them use this code

.setValue('input[type=password]', ['', [browser.Keys.CONTROL, "a"]])
.keys('\uE017') // delete them using delete key

hopes that works for you all

I use a function to get a working "clearValue"

/**
 * A better `clearValue` for inputs having a more complex interaction.
 *
 * @export
 * @param {string} selector
 * @returns
 */

exports.command = function clearValue2 (selector) {
  const { RIGHT_ARROW, BACK_SPACE } = this.Keys
  return this.getValue(selector, (result) => {
    const chars = result.value.split('')
    // Make sure we are at the end of the input
    chars.forEach(() => this.setValue(selector, RIGHT_ARROW))
    // Delete all the existing characters
    chars.forEach(() => this.setValue(selector, BACK_SPACE))
  })
}

This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

:+1:

I've been trying to adopt workarounds suggested by @MonrealRyan and @MartinX3, and I've noticed that Keys object is accessed in a different way in my case (Nightwatch 1.3.6), so you'd need to change it like this:

// for solution by MonrealRyan
.setValue('input[type=password]', ['', [browser.api.Keys.CONTROL, "a"]])

// for solution by MartinX3
const { RIGHT_ARROW, BACK_SPACE } = this.api.Keys

// Google Chrome 87
// maybe you can use "backspace" -> \u0008
.setValue('input[type=password]', ['\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008', '\u0008'])

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Pieras2 picture Pieras2  路  3Comments

antogyn picture antogyn  路  4Comments

chaseconey picture chaseconey  路  4Comments

danielbentov picture danielbentov  路  4Comments

t00f picture t00f  路  3Comments