JavaScript设置密码DIV值不起作用

时间:2018-12-07 12:10:36

标签: javascript

我想使用Threema Web,而不必每次都输入此愚蠢的密码。该网站为https://web.threema.ch/#!/welcome

如果不输入密码,则每次刷新页面时都需要重新配对手机。输入密码,然后要求您在每次刷新/重新启动后输入密码。

我想自动输入密码和登录名,因为我的PC已经安全了。

我尝试过以下操作:

    //get the wrapping DIV
loginDiv = document.getElementsByClassName('password-entry')[0]  
loginPane = loginDiv.children[0]

    //find the password field
passwordPane = loginPane.children[1]
passwordLabel = passwordPane.children[0]  
passwordDiv = passwordLabel.firstChild
passwordInput = passwordDiv.nextSibling

    //set the password value
passwordInput.value = "0000"

console.log(passwordInput)

    //find and click the "login" button
buttonDiv = passwordPane.children[1]
buttonDiv.click()

运行此命令将使密码占位符文本消失。但是,它将告诉您密码错误。在密码字段中预先键入随机文本,然后运行Javascript,将使密码字段显示与脚本密码中包含的字符一样多的审查气泡。但是,这仍然会显示“密码错误”错误。

我也尝试过处理虚拟键盘事件,但这没用。

我认为可能会有一些底层的JS在每个字符之后设置密码,但是我不知道如何定位/解决这个问题。

对于如何解决此问题的想法将不胜感激。

密码的div就是这样

<input type="password" ng-model="ctrl.password" ng-disabled="ctrl.formLocked" autofocus="" aria-labelledby="aria-label-password-reconnect" translate-attr="{'placeholder': 'welcome.PASSWORD'}" autocomplete="current-password" class="ng-valid md-input ng-touched ng-dirty ng-valid-parse ng-empty" id="input_0" aria-invalid="false" placeholder="Password" style="" value="a">

但是我认为这与底层JS有关。

这是文本字段周围的区域

<div class="password-entry">
                <label>
                    <p translate="" id="aria-label-password-reconnecte" class="ng-scope"> text </p>
                    <form ng-submit="ctrl.unlockConfirm()" class="ng-pristine ng-valid">
                        <md-input-container md-no-float="" class="md-block">
                            <input type="password" ng-model="ctrl.password" ng-disabled="ctrl.formLocked" autofocus="" aria-labelledby="aria-label-password-reconnect" translate-attr="{'placeholder': 'welcome.PASSWORD'}" autocomplete="current-password" class="ng-pristine ng-valid md-input ng-empty ng-touched" id="input_0" aria-invalid="false" placeholder="Passwort" style=""><div class="md-errors-spacer"></div>
                        </md-input-container>
                        <button class="md-raised md-primary md-button ng-scope md-ink-ripple" type="submit" ng-transclude="" translate="" translate-attr-aria-label="welcome.BTN_RECONNECT" aria-label=" text ">
                            <span translate="" aria-hidden="true" class="ng-scope"> text </span>
                        </button>
                    </form>
                    <p>
                        <span translate="" class="ng-scope"> text:</span>
                        <a href="#" ng-click="ctrl.deleteSession()" translate="" class="ng-scope">text </a>.
                    </p>
                </label>
            </div>

2 个答案:

答案 0 :(得分:0)

只需将密码字段作为目标并使用setAttribute方法设置值:

document.querySelector('[type="password"]').setAttribute('value', '1234');

答案 1 :(得分:0)

由于您要定位元素中的type="password"字段,因此可以使用Element#querySelector

loginDiv = document.getElementsByClassName('password-entry')[0]  
loginPane = loginDiv.children[0]
// ...
passwordInput = loginPane.querySelector("[type=password]");
passwordInput.value = "0000";
相关问题