Windows system with the Internet Explore + Plus PowerShell can be done.
Today to share the next few days I wrote several small functions, welcome to Pat Bricks:
# Open IE Window # function New-iewindow {param ([string] $Url, [switch] $Visible, [switch] $FullScreen) $Global: IEH ost = new-object-com "Internetexplorer.application" $Global: Iehost.navigate ($URL) #设置IE可见性和全屏 $Global: Iehost.visi ble= $Visible $Global: iehost.fullscreen= $FullScreen} # #等待IE加载完毕 # function Wait-ieready ([int] $TimeoutSeconds =10 {$milliseconds =0 $maxMilliseconds = $TimeoutSeconds * 1000 while ($Global: iehost.busy) {if ($millisecond
S-gt $maxMilliseconds) {throw ' Wait ie ready timeout. ' Sleep-milliseconds $milliseconds +=100} # # Get HTML element # function based on Id,class,name,tag get-htmlelement
($Id, $Name, $Class, $Tag) {if ($Id) {return $IEHost. document.getElementById ($id)} elseif ($Name) {return $IEHost. Document.getelementsbyna Me ($Name)} elseif ($Class) {$IEHost. document.all | where {$_.classname-contains $Class}} elseif ($Tag) {$IEHo St. document.getElementsByTagName ($Tag)}} # #关闭IE Window # function Close-iewindow {$Global: Iehost.quit () remove-variable Iehost-force} # #设置IE的地址 # function Navigat E-ie ($URL) {Set-ie-url $URL} # Set IE's address, or action: Forward, rewind, refresh # function Set-ie {param ([Validateset (' GoBack ', ' Goforwar d ', ' Refresh ')] [string] $Action, [URI] $URL) # action switch ($Action) {(' GoBack ') {$Global: Iehost.goback ()} (' Gofor Ward ') {$Global: Iehost.goforward ()} (' Refresh ') {$Global: Iehost.refresh ()}} # Set IE address if ($URL) {$Global: IEHost. Navigate ($URL)} # # Execute script # function Invoke-iescript ($Code, $Language = ' Javascript ') in IE window {if-not [String]::isnullo
Rwhitespace ($Code)) {$Global: IEHost.Document.parentWindow.execScript ($Code, $Language)}}