2013-03-06 71 views
-1

我正在嘗試將我的憑據放入網站,以便自動執行一些任務。我正在嘗試這個代碼。沒有任何反應。故障自動化Internet Explorer

$Url = "https://srvdcvs05.fiep_pr.br:1311/" 
$Ie = New-Object -Com InternetExplorer.Application 
$Ie.Navigate($Url) 
$secLink = $Ie.Document.getElementsByTagName('A') | Where-Object {$_.innerText -eq 'Continue to this website (not recommended).'} 
$secLink.click() 
$Ie.Document.getElementsByType("input") | where { $.Name -eq "user" }.value = "myuser" 
$Ie.Document.getElementsByName("input") | where { $.Name -eq "password" }.value = "mypassword" 
$loginBtn = $Ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'button' -and $_.Value -eq 'LoginButton'} 
$loginBtn.click() 

回答

1

很難說不知道頁面的任何內容。

話雖這麼說,兩個明顯的錯誤,可能是這個原因吧:

# Your code: $Ie.Document.getElementsByType("input") | where { $.Name -eq "user" }.value = "myuser" 
($Ie.Document.getElementsByType("input") | where { $_.Name -eq "user" }).value = "myuser" 
# Your code: $Ie.Document.getElementsByName("input") | where { $.Name -eq "password" }.value = "mypassword" 
($Ie.Document.getElementsByName("input") | where { $_.Name -eq "password" }).value = "mypassword" 

所以:訪問屬性腳本塊沒有意義({ }.value)和where需求$_.Property而非$.Property

1

感謝您的重播。

關於它「$ _。Property而不是$ .Property。」打錯了,對此感到遺憾。

但是...我最初的問題是這樣的功能:

$ secLink = $ Ie.Document.getElementsByTagName( 'A')|位置對象{$ _。innerText屬性-eq '繼續瀏覽此網站(不推薦)。'}

$ secLink.click()

不起作用。該網站打開,但沒有點擊此消息。