我有关于“用户名”的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
答案 0 :(得分:1)
这是因为您的控件位于框架内。你必须这样做:
$ie.Document.getElementById("gsft_main").contentWindow.document.getElementByID("user_name").value = "UserName"