PowerShell 抛出错误提示 Click() 不存在

PowerShell throws error saying Click() does not exist

我正在练习使用 PowerShell,今天我想我应该编写一个脚本来登录网站。我对这个具体示例没有用处,但我认为这是一个很好的做法。我在引用 this 时创建了它。这是我目前所拥有的。

$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.Visible = $true

$username = "my@email"
$password = "password"

$ie.Navigate("https://squirrel.ws/login")

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

$usernameField = $ie.Document.getElementByID('UserEmail')
$usernameField.value = $username

$passwordField = $ie.Document.getElementByID('UserPassword')
$passwordField.value = $password

$link = $ie.Document.getElementByID('[=10=]')
$link.click()

$ie.Quit()

当我 运行 这个时,IE window 出现,并且几乎立即关闭并出现此错误:

Method invocation failed because [System.DBNull] does not contain a method named 'click'.
At J:\removingForPrivacy\test.ps1 char:1
+ $link.click()
+ ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

所以我很确定它会在尝试单击时抛出错误,或者因为我错误地标记了按钮,或两者兼而有之。尝试创建此按钮时,我找不到该按钮的 ID,因此我使用了我能找到的 ID。否则我不确定为什么 click() 在我看到的所有示例中都不存在。有人可以帮助我吗?

我的问题是在创建 $Link 时使用了错误的标签。我使用了所有相同的代码,但将 $Link 创建行换成了:

$Link=$ie.Document.getElementsByTagName("button") | where-object {$_.type -eq "submit"}