HTML问题/通过Powershell激活

时间:2018-10-18 15:39:46

标签: html powershell login

我觉得我有很多问题要负担,但是我也知道,如果这意味着帮助另一个程序员理解和解决问题,您就不会在这里读这篇文章:)

因此,我试图做一个简单的按钮,使用户可以访问网站,登录,直接进行时间管理,然后单击“记录时间戳”按钮。基本上,只需单击一下即可登录/关闭按钮。

问题是,该网站不允许我自动填写用户名和密码字段,并且不允许程序单击“登录”按钮。参见下面的代码:

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form_Login                    = New-Object system.Windows.Forms.Form
$Form_Login.ClientSize         = '200,165'
$Form_Login.text               = "Login/Logout"
$Form_Login.TopMost            = $false
$Form_Login.StartPosition      = 'CenterScreen'

$label_Login                   = New-Object system.Windows.Forms.Label
$label_Login.text              = "Click to login/logout"
$label_Login.AutoSize          = $true
$label_Login.width             = 25
$label_Login.height            = 10
$label_Login.location          = New-Object System.Drawing.Point(40,10)
$label_Login.Font              = 'Microsoft Sans Serif,10'
$label_Login.ForeColor         = "#000000"

$Button_Login                  = New-Object system.Windows.Forms.Button
$Button_Login.text             = "Login/Logout"
$Button_Login.width            = 180
$Button_Login.height           = 125
$Button_Login.location         = New-Object System.Drawing.Point(10,30)
$Button_Login.Font             = 'Microsoft Sans Serif,10'

$Form_Login.controls.AddRange(@($label_Login,$Button_Login))

$Button_Login.Add_Click({

    $ie = New-Object -ComObject 'internetExplorer.Application'
    $ie.Visible= $true # Make it visible

    $username="username"

    $password="password"

    $ie.Navigate("https://workforcenow.adp.com/workforcenow/login")

    While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}

    $usernamefield = $ie.document.getElementByID('user_id')
    $usernamefield.value = "$username"

    $passwordfield = $ie.document.getElementByID('password')
    $passwordfield.value = "$password"

    $Link = $ie.document.getElementByID('subBtn')
    $Link.click()

})

[void]$Form_Login.ShowDialog()

因此,当我运行脚本时,它会填写字段,但是按钮显示为灰色。我想念什么? HTML代码中有东西吗?

谢谢你们!祝你有美好的一天!

2 个答案:

答案 0 :(得分:0)

您可以像这样手动触发OnKeyUp事件:

$usernamefield.FireEvent('onKeyUp')
$passwordfield.FireEvent('onKeyUp')
#Side note, the equal length variable names here are just...*chef's kiss*

您可能需要在Chrome开发工具中打开页面,并查看网站的JavaScript,以确保这是他们关注的事件。他们可能正在等待其中的一个或两个都发送密钥,或者正在等待将鼠标悬停在“提交”按钮上。

也许按钮本身需要启用?

这两种方法都可以帮助您入门。

答案 1 :(得分:0)

让我们谈谈HTML

在里面我们看到一些东西

<button disabled="" class="btn btn-primary ng-scope" id="subBtn" type="submit" data-ng-click="saveUserID()" translate="signin.signin">Sign In</button>

我们本可以提交这样的表格

$Form = $passwordfield.Form
$Form.Submit()

但是我们在按钮内部看到ng-click="saveUserID()",它指向提交表单之前帖子发生的一些javascript处理,这意味着我们需要单击该按钮。在按钮上,我们看到disabled="",这是用于使按钮不可单击的属性。因此,我们要做的就是删除该属性。

$Link = $ie.document.getElementByID('subBtn')
$Link.removeAttribute("disabled");
$Link.click()

这将提交表格。

相关问题