我試圖用powerhell在IE 21H版上下載檔案。
當我使用Powershell點擊下載按鈕時,它要求我在下載彈出視窗中進行以下按摩。
你想從www.XYZ.com打開或保存XYZ.log。 下面是我使用的代碼
$ie = New-Object -ComObject 'InternetExplorer.Application'
$ie.Viscible=$true
$ie.Navigate("www.xyz.com/ab/sder23445sdfrty") #請注意這是我提供的隨機URL。
$link=$ie.Document。 getElementsByTagName("Button") | where-object {$_.outerhtml - like "*download*"}。
$link.click()
uj5u.com熱心網友回復:
你可以先激活IE視窗,用AppActivate把它帶到前面,然后用SendKeys發送按鍵Ctrl S來保存檔案。
示例代碼如下,你可以改變你的url和元素選擇器。
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms"/span>)
[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$ie = New-Object -ComObject 'InternetExplorer.Application'
$ie.Viscible=$true
$ie.Navigate("https://www.example.com/download.html") #change it to your own url.
while($ie. ReadyState -ne 4 -or $ie.Busy) {Start-Sleep -m 100}。
$link=$ie.Document.getElementById("btnDowload") #change it to your own selector.
$link.click()
睡眠5。
$ieProc = Get-Process | ? { $_.MainWindowHandle -eq $ie.HWND }
[Microsoft.VisualBasic.Interaction]::AppActivate($ieProc.Id)
[System.Windows.Forms.SendKeys]::Sendwait("%{s}") 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/320208.html
標籤:
