PowerShell technology to realize IE Web Automation _powershell

Source: Internet
Author: User

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)}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.