首页 > 解决方案 > 使用 HTML 表单作为 GUI PowerShell 时出现 innerHTML 错误

问题描述

使用 HTML 表单作为 powershell 的 GUI

下面的代码工作正常,但是,在 Azure VM 上使用它时出现错误

=============错误==============

Error- 
The property 'innerHTML' cannot be found on this object. Verify that the 
property exists and can be set.
At line:24 char:1
+ $ie.document.body.innerHTML = $html
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
***

=================代码=================

$html = @"
<HTML>
<body>
<form>
First name: <input type="text" id="firstname">
<br>
Last name: <input type="text" id="lastname">
<br>
<input type="hidden" name="finished" value="0">
<input type="button" id="button" value="Continue"onclick="finished.value=1">
</form>
</body>
</html>
"@

$ie = new-object -com "InternetExplorer.Application"
$ie.navigate2("about:blank")
$ie.AddressBar  = $false
$ie.MenuBar     = $false
$ie.StatusBar   = $false
   
$ie.document.body.innerHTML = $html
$ie.Visible = $true
$doc = $ie.document
   
while ($doc.getElementByID("finished").value -ne 1) {
    start-sleep -m 500
}
   
$ie.Visible = $false
"You answered:"
$doc.getElementByID("firstname").value
$doc.getElementByID("lastname").value
$ie.quit()

标签: javascripthtmlazurepowershellinnerhtml

解决方案


推荐阅读