我是PowerShell的新手,我正在尝试自动登录网站,我浏览过很多例子但NONE工作没有错误。
例如,使用这个非常简单的脚本:
$ie = New-Object -comobject InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate($URL)
$ie.Navigate("www.facebook.com")
$ie.document.getElementById("pass")
$ie.document.getElementById("pass").value = "Hi"
我应该得到"嗨"在密码字段中,但我得到了这个
我发现的所有例子中都出现了这个错误,发生了什么?这是Powershell不再支持的内容吗?
我有Windows 10。
答案 0 :(得分:2)
请勿使用getElementById
。使用IHTMLDocument3_getElementById
,例如:
$ie.Document.IHTMLDocument3_getElementById("email").value = "asd123"
您也可以为其他方法执行此操作,例如IHTMLDocument3_getElementsByName
。
我应该补充一点,我不知道为什么这是有效的 - 我只是使用以下查询在Document对象上找到任何有用的查找成员并使用它们来玩它们
$ie.Document | Get-Member | where Name -like '*get*'