【发布时间】:2020-08-07 01:43:53
【问题描述】:
我很难在应用程序浏览器中捕获搜索的输出。
要求: 1. 登录申请网址。 2.搜索 3.捕获结果
我有一个代码,它在一台服务器上运行良好,但在其他机器上表现得很奇怪。 powershell 版本和 IE(11) 都是一样的。在好的服务器上,一切正常。在坏的服务器上,powershell 无法仅获取第 3 点的元素和类名。它每次都捕获空字符串。甚至 $ie.Document.getElementsByTagName("body") 在坏服务器上返回空。
我是 powershell 新手,不确定我是否错过了任何东西。有人可以在这里提出想法吗?
下面是代码:
$username = "user1"
$password = "pwd1"
$url="application URL"
$search="tamanna"
$ie = New-Object -ComObject 'InternetExplorer.Application'
$ie.visible=$true
$ie.navigate($url)
while($ie.ReadyState -ne "4")
{
start-sleep -Seconds 5;
}
($ie.document.getElementById("login-form-username") |select -first 1).value = $username;
($ie.document.getElementById("login-form-login-password") |select -first 1).value = $password;
$ie.document.getElementById("login-form-login").click()
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 5; }
$ie.navigate("Search URL within application")
while ($ie.ReadyState -ne "4") { Start-Sleep -Seconds 5; }
$text=$ie.Document.getElementsByTagName("span") | Where-Object{$_.className -eq 'class1_unique'} |select -first 1
while ($ie.ReadyState -ne "4") { Start-Sleep -Seconds 5; }
$searchResult=$text.innerText
$searchResult
【问题讨论】:
标签: html powershell internet-explorer dom automation