属性 'value' 在 Powershell 中无法在此对象上找到
Property 'value' cannot be found on this object in Powershell
我想在我的脚本中设置 'User Name' 的 HTML。
<input id="user_name" value="" autocomplete="off" type="text" name="user_name">
这是我为实现它而编写的 powershell 代码:
$ie = new-object -com InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate("https://abcdnow.com/navpage.do")
while ($ie.Busy) {start-sleep -s 3}
$ie.Document.getElementByID("user_name").value = "Username"
$ie.Document.getElementByID("user_password").value = "Password"
这是我收到的错误:
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At D:\servicenow.ps1:7 char:1
+ $ie.Document.getElementByID("user_name").value = "Username"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
这是因为您的控件位于框架内。你必须这样做:
$ie.Document.getElementById("gsft_main").contentWindow.document.getElementByID("user_name").value = "UserName"
我想在我的脚本中设置 'User Name' 的 HTML。
<input id="user_name" value="" autocomplete="off" type="text" name="user_name">
这是我为实现它而编写的 powershell 代码:
$ie = new-object -com InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate("https://abcdnow.com/navpage.do")
while ($ie.Busy) {start-sleep -s 3}
$ie.Document.getElementByID("user_name").value = "Username"
$ie.Document.getElementByID("user_password").value = "Password"
这是我收到的错误:
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At D:\servicenow.ps1:7 char:1
+ $ie.Document.getElementByID("user_name").value = "Username"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
这是因为您的控件位于框架内。你必须这样做:
$ie.Document.getElementById("gsft_main").contentWindow.document.getElementByID("user_name").value = "UserName"