-1

I am working on an automatic login feature by filling in the username and password for a web application using javascript. The password field has the autocomplete feature activated. It's HTML is as below -

<input name="autofill_password" type="password" style="display:none">
<input name="user_password" type="text" onfocus="this.setAttribute('type', 'password')" id="user_password" maxlength="256" class="loginField" autocomplete="new-password">

I am unable to set the value using javascript or jquery for the "user_password" field. I have tried the following with no luck -

$('#user_password').val("g");
$('#user_password').attr('value', 'new value');
document.getElementById('user_password').value = 'Welcome!1';
document.getElementById('user_password').setAttribute('type', 'text');

What is preventing the setting of the value and what else can I try?

6
  • 2
    The code you've shown works fine: jsfiddle.net/RoryMcCrossan/1o5hztg9. Check the console for errors Commented May 26, 2021 at 9:20
  • 3
    Also, having an auto-complate feature on a password field in client-side JS seems like an incredibly bad idea for security. Commented May 26, 2021 at 9:21
  • 1
    @RoryMcCrossan just to showcase that all three approaches work Commented May 26, 2021 at 9:23
  • 1
    Autocomplete on a password field is probably going to be complicated and browser specific. Why not use the autocomplete features already built into browsers and plugins like Lastpass? Commented May 26, 2021 at 9:42
  • Actually we are trying to automate navigation and input into a portal with no access to the source code Commented May 26, 2021 at 9:49

1 Answer 1

0

So, this is for all the other simpletons like me, the issue was, that there was a label with the same id as password field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.