我收到以下错误消息,当我运行我的PowerShell脚本自动登录到网站上使用PowerShell
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Test.ps1:17 char:1
+ $usernamefield.value = $username
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Test.ps1:20 char:1
+ $passwordfield.value = $password
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Method invocation failed because [System.DBNull] does not contain a method named 'click'.
At C:\Test.ps1:23 char:1
+ $Link.click()
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound`
我的脚本:
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible
$usernmae="test"
$password="test1"
$ie.Navigate("https://website.com/login")
While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}
$usernamefield = $ie.document.getElementByID('ysi_email')
$usernamefield.value = $username
$passwordfield = $ie.document.getElementByID('ysi_password')
$passwordfield.value = $password
$Link = $ie.document.getElementByID('ysi_btn_login')
$Link.click()
我似乎无法理解的问题在这里,我已经看到了其他的例子,但我仍然无法找到问题。
在Python脚本的另一个例子中,相同的id可以正常工作。
如果你这样设置,同样的问题? $ ie.document.getElementByID('ysi_email')。value = $ username – Esperento57
你的名字是'ysi_email'吗? – Esperento57
是的,请看附件截图。这个ID适用于python和chrome,但没有使用powershell和IE? – irish