【发布时间】:2019-06-21 03:05:39
【问题描述】:
我正在练习使用 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('$0')
$link.click()
$ie.Quit()
当我运行它时,会出现一个 IE 窗口,并且几乎立即关闭并显示以下错误:
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,所以我使用了我能找到的东西。否则我不确定为什么click() 在我看到的所有示例中都不存在。有人可以帮帮我吗?
【问题讨论】:
标签: powershell internet-explorer click