我在嘗試登錄,然後導航到頁面,然後在第二頁上設置元素值並提交它們。但是PowerShell一直在說元素不存在。所以要排除故障,我想寫一個文本文件我正在瀏覽的頁面的內容。下面的腳本創建一個空白的文件。有任何想法嗎?Powershell找不到元素
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate($URL)
while ($ie.Busy -eq $true)
{
Start-Sleep -Milliseconds 1000;
}
$ie.Document.getElementById("userId").value = $username
$ie.Document.getElementByID("userPassword").value=$password
$ie.Document.getElementById("login").Click();
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; }
Start-Sleep -Milliseconds 10000;
#$ie.Document.getElementById("officeList").action ="edit.jsp";
#$ie.Document.getElementById("officeId").value="1234";
#$ie.Document.getElementById("officeList").submit();
$ie.navigate($URL2)
$ie.document.documentelement.innertext |out-file C:\Users\me\Documents\PowerShell\html.txt
您是否調試過該功能?我在'Start-Sleep -Milliseconds 10000'上設置了一個斷點,看看實際的瀏覽器窗口是什麼樣的。同樣,在'$ ie.navigate($ URL2)'調用之後,瀏覽器窗口是什麼樣的? –
是的,我看着IE窗口,它有內容。 – prike