首页 > 解决方案 > Powershell 自动登录到网站.....$ie.Document.getElementsByClassName

问题描述

我正在尝试设置一个 PowerShell,它将让我登录到我儿子的学校门户并提交所需的表格。我必须每天做一个,并且得到了可以编写脚本的好主意。该脚本与错误一起在下面

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

$username="Username"

$password="Password"

$ie.Navigate("https://parents.genesisedu.com/hasbrouckheights/parents?module=home&studentid=1000333&action=form")

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

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

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

$Link = $ie.Document.getElementsByClassName(“saveButton”)[0].value="Login"
$Link.click()

Method invocation failed because [System.String] does not contain a method named 'click'.
At line:19 char:1
+ $Link.click()
+ ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

我尝试了很多变化,但似乎无法让它点击“登录”按钮。任何帮助将不胜感激......

*************** 网站信息 ************************

<input type="submit" class="saveButton" style="color: #000000;background-color: #e0e0e0; font-weight: 500;" value="Login">

<input type="button" class="saveButton" value="Forgot My Password" style="background-color:#e0e0e0; border:transparent; cursor:pointer;color:#000; font-size: 12pt; font-weight:500" onclick="forgotMyPassword();">

谢谢

标签: powershell

解决方案


您当前在调用之前将字符串值分配给"Login",因此出现错误。$LinkClick()

改变这个:

$Link = $ie.Document.getElementsByClassName(“saveButton”)[0].value="Login"

... 至:

$Link = $ie.Document.getElementsByClassName(“saveButton”)[0]

推荐阅读