'Automation sign-in to Apple homepage not working

I am trying to make an automation sign-in on the Apple homepage for a reason. It's not about 'sign-in with Apple'. I just need a simple sign-in action as below.

  1. Open the Apple Login page with a new Chrome tab. (done)
  2. Fill in the id and password inputs.
  3. click the sign-in button.

So I wrote this function.

function appleLoginAction(userid, userpasswd) {
    var _parent = document.getElementById('aid-auth-widget-iFrame');
    var idField = _parent.contentDocument.getElementById('account_name_text_field');
    setTimeout(function () {
        if (idField != 'undefined') {
            idField.value = userid;
        }
    }, 10);

    var div = _parent.contentDocument.getElementById('sign_in_form');
    div.classList.remove('hide-password');
    div.classList += ' account-name-entered';
    div.classList += ' show-password';

    var signInBtn = _parent.contentDocument.getElementById('sign-in');
    signInBtn.ariaDisable = "false";
    signInBtn.click();

    var btn1 = _parent.contentDocument.querySelector('.password form-row');
    setTimeout(function () {
        btn1.click();
    }, 10);

    var passwdField = _parent.contentDocument.getElementById('password_text_field');
    setTimeout(function () {
        if (passwdField != 'undefined') {
            passwdField.value = userpasswd;
        }
    }, 10);
    div.classList += ' password-entered';

    var btn2 = _parent.contentDocument.querySelector('#sign-in');
    btn2.removeAttribute('disabled');
    setTimeout(function () {
        btn2.click();
    }, 10);
}

However, it could fill the id and password inputs, but it doesn't work.
The message says I put the wrong id, but I put the correct id.
I guess there is a validation system before I fill the password input, but I couldn't figure it out.
Would it be impossible to automate this sign-in to the Apple homepage as I want?

The sign-in page URL is HERE



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source