internetexplorer.application document.getElementByID返回为null/Powershell [英] internetexplorer.application document.getElementByID returns as null / Powershell
本文介绍了internetexplorer.application document.getElementByID返回为null/Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
努力解决以下问题.
请参见HTML的摘录,其中存在ID,但ID始终返回空表达式.不幸的是,我无法在网站上提供更多详细信息.
See the extract of the HTML, the ID is present but it keeps returning a null expression. Unfortunately I cant give any more details on the website... Anything obvious to what I'm doing wrong?
--- HTML的提取----
--- Extract of HTML ----
<input name="ctl00$mainCopy$LoginView$LoginControl$UserName" type="text" id="ctl00_mainCopy_LoginView_LoginControl_UserName" tabindex="1" class="txtBox" onchange="document.getElementById('ctl00_mainCopy_LoginView_LoginControl_PasswordResetLink').disabled
= false;" style="width:150px;" />
-脚本---
$ie = New-Object -com internetexplorer.application
$ie.visible = $true
$ie.navigate("excluded for security")
$ie.document.getElementByID("ctl00_mainCopy_LoginView_LoginControl_UserName").Value= "excluded for security"
----错误----
---- Error ----
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $ie.document.getElementByID("ctl00_mainCopy_LoginView_LoginControl_UserName").Va ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
推荐答案
尝试在$ie.navigate
命令之后进行睡眠,例如:
Try putting a sleep after the $ie.navigate
command, such as this:
while ($ie.Busy() -and $ie.ReadyState -ne 4){ sleep -Milliseconds 100 }
当您尝试获取元素时,页面似乎仍在加载.
It looks like your page is still loading when you attempt to get an element.
这篇关于internetexplorer.application document.getElementByID返回为null/Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文