Clockify中的登录表单

Fab*_*rdo 6 javascript powershell angular2-changedetection clockify

我正在尝试创建一个PowerShell脚本来打开Internet Explorer,导航到https://clockify.me/login,填写电子邮件和密码输入并提交表单或单击登录按钮.

问题是,在使用以下方法填充输入时:

  • document.getElementById("email").value="123"
  • document.getElementById("password").value="123"

我有以下结果:

  • 当我提交表格时document.forms[0].submit(),网页重新加载网址https://clockify.me/login?email=&password=并且没有任何反应
  • 当我单击按钮,使用javascript或手动时,它认为输入为空

那么,有没有办法解决这个问题?使用纯粹的javascript或PowerShell(我希望保持IE窗口不可见)

谢谢!

use*_*768 10

即使您正在更改inputDOM对象的值,这也不足以触发底层Angular库的更改检测,从而使表单显示为"空".

以下纯JS示例适用于Chrome,但我尚未在Internet Explorer中对其进行测试:

let email = document.getElementById("email");
let password = document.getElementById("password");
let button = document.getElementsByTagName("button")[0];

email.value = 'someone@example.com';
password.value = 'yourpassword';

// Trigger change detection
email.dispatchEvent(new Event('input'));
password.dispatchEvent(new Event('input'));

button.click();
Run Code Online (Sandbox Code Playgroud)

如果dispatchEvent在IE中不起作用,您可以尝试使用createEventinitEvent.请参阅在IE11中不能使用的dispatchEvent