正在尝试将Powershell中的getElementById与IE 11一起使用,HRESULT中出现错误异常:0x800A01B6

正在尝试将Powershell中的getElementById与IE 11一起使用,HRESULT中出现错误异常:0x800A01B6,powershell,internet-explorer-11,powershell-5.0,Powershell,Internet Explorer 11,Powershell 5.0,我正在尝试自动登录网站,但似乎无法使用getElementById。getElementsByClassName(“任意”)[0]似乎可以工作,但我需要的元素没有类名,我无法更改 我用的是PS 5,即11。下面是我的代码示例,以及由此产生的异常 $url = "https://google.com" $ie = New-Object -com "InternetExplorer.Application" $ie.visible = $true $ie.navigate($url) while (

我正在尝试自动登录网站,但似乎无法使用getElementById。getElementsByClassName(“任意”)[0]似乎可以工作,但我需要的元素没有类名,我无法更改

我用的是PS 5,即11。下面是我的代码示例,以及由此产生的异常

$url = "https://google.com"
$ie = New-Object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($url)
while ($ie.Busy){Start-Sleep -Milliseconds 1000}
$ie.document.getElementById("lst-ib").value = "test"
错误:

Exception from HRESULT: 0x800A01B6
At C:\gtest.ps1:6 char:1
+ $ie.document.getElementById("lst-ib").value = "test"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], NotSupportedException
    + FullyQualifiedErrorId : System.NotSupportedException
登录谷歌

$r = Invoke-WebRequest "https://google.bg" -SessionVariable g

$r = Invoke-WebRequest 'https://accounts.google.bg/' -WebSession $g

$r.Forms['gaia_loginform'].Fields.Email = 'someuser@gmail.com'
$r.Forms['gaia_loginform'].Fields.Passwd = 'somepass'

$r = Invoke-RestMethod $r.Forms['gaia_loginform'].Action -Body $r.Forms['gaia_loginform'] -Method $r.Forms['gaia_loginform'].Method  -WebSession $g

$r = Invoke-WebRequest https://google.bg -WebSession $g

$r.Content > tmp2.html
希望对您有所帮助

尝试使用

$ie.Document.documentElement.getElementByClassName();
$ie.Document.documentElement.getElementByTagName();
$ie.Document.documentElement.getAttribute();
对于id名称标记名,请使用

$ie.Document.IHTML3_getElementById();
$ie.Document.IHTML3_getElementByName();
$ie.Document.IHTML3_getElementByTagName();

为什么不呢,谢谢,现在就试试。但是,在设置表单字段后,无法确定如何提交它。获取错误:Invoke RestMethod:无法验证参数“Uri”上的参数。参数为null或为空。请提供一个不为null或空的参数,然后重试该命令$r=调用RestMethod$r.Forms[0]。操作-Body$r.Forms[0]方法$…它应该可以工作。你在谷歌上试用吗?如果不检查你的表单的“动作”——如果它是一个“完整”的url,那么不是相对的etcIt在谷歌上工作,但不是在我真正需要它的地方。我正在使用Fiddler Web调试器查看HTTP请求,以查看我缺少的内容,但我不太了解这些内容。正在尝试登录到打印机<代码>邮政http://PrinterIP/login.html?/main.html HTTP/1.1主机:PrinterIP连接:keep-alive-Accept:text/html、application/xhtml+xml、application/xml;q=0.9,图像/webp,*/*;q=0.8原点:http://printerIP 升级不安全请求:1内容类型:应用程序/x-www-form-urlencoded ggt_选择%2810009%29=3&ggt_文本框%2810003%29=admin&action=loginbtn&纵坐标=0&ggt_隐藏%2810008%29=5idk,我会尝试“手动”构造标题和正文,并仅使用sessin变量跟踪任何coockies。。。不使用“-Body$r.Forms['gaia_loginform']”,而是将字符串“ggt_select%2810009%29=3&ggt_文本框%2810003%29=admin&action=loginbtn&logy=0”组合在一起&‌​ggt_hidden%2810008%29=5'我自己和诸如此类的人,但是的,Fiddler是工具,我尝试匹配我所看到的there@Alberto有时,当页面加载正确或不正确时,我们无法访问
DocumentElement
,因此
IHTML3..
也会这样做