Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clearValue is not clearing input type=password field #1592

Closed
vedmant opened this issue Sep 21, 2017 · 12 comments
Closed

clearValue is not clearing input type=password field #1592

vedmant opened this issue Sep 21, 2017 · 12 comments
Labels

Comments

@vedmant
Copy link

vedmant commented Sep 21, 2017

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.

@davidlinse
Copy link
Contributor

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

@vedmant
Copy link
Author

vedmant commented Nov 21, 2017

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

@farhadf246
Copy link

farhadf246 commented Aug 19, 2018

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)

@stormaref
Copy link

@farhadf246 thanks a lot it worked fine 😀😀

@MartinX3
Copy link

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

@JGjumpshot
Copy link

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

@MonrealRyan
Copy link

MonrealRyan commented Mar 14, 2019

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@email.com')

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

@MartinX3
Copy link

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

@stale
Copy link

stale bot commented Jun 24, 2019

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.

@stale stale bot added the stale label Jun 24, 2019
@stale stale bot closed this as completed Jul 1, 2019
@lusarz
Copy link

lusarz commented Apr 17, 2020

👍

@Sc4ramouche
Copy link

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

@hongdeyuan
Copy link

hongdeyuan commented Nov 25, 2020

// 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'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants