2015-09-04 107 views
2

我在嘗試登錄,然後導航到頁面,然後在第二頁上設置元素值並提交它們。但是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 
+0

您是否調試過該功能?我在'Start-Sleep -Milliseconds 10000'上設置了一個斷點,看看實際的瀏覽器窗口是什麼樣的。同樣,在'$ ie.navigate($ URL2)'調用之後,瀏覽器窗口是什麼樣的? –

+0

是的,我看着IE窗口,它有內容。 – prike

回答

-1

你確定你的元素叫userId和userPassword等嗎?您可以在瀏覽器中按F12時檢查它們

+0

今後請注意,這不是一個問題的答案,應該是一個評論 – MarshallOfSound

+0

啊先在這裏評論..不知道。我做了這樣的事情: $ IE = New-Object -com internetexplorer.application; $ IE.visible = $ true; $ IE.navigate($ url2); $ ie.fullscreen = $ true; 啓動睡眠-s 3 $ IE.Document.getElementById( 「login_username」)。值= $ USERNAME2 $ IE.Document.getElementByID( 「login_password」)。值= $密碼2 啓動睡眠-s 1 $ IE.Document.getElementById(「Login」)。submit() – Dennis

+0

我也有同樣的錯誤,解決了我的開始睡覺。我不得不調整他們才能讓它恰到好處。 該網站正在加載緩慢.. – Dennis