Created
September 11, 2019 13:15
-
-
Save GER-NaN/4542f282cc819b622576a80ec2f088ac to your computer and use it in GitHub Desktop.
More powershell automation of the IE web browser. These are specific to my app and stand as an example only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Needs to be ran as administrator | |
| #Logs in as user and creates a generic listing | |
| ##hacker-line that causes this script to run in a new session as administrator if not already elevated | |
| #if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) | |
| #{ | |
| # Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; | |
| # exit | |
| #} | |
| #sleep so we can see events happening on screen | |
| function Sleep-UI($milliseconds){ | |
| if($milliseconds -eq $null) | |
| { | |
| $milliseconds = 225 | |
| } | |
| $sleepTime = $milliseconds | |
| Start-Sleep -Milliseconds $milliseconds | |
| write-host 'sleep for UI' | |
| } | |
| #polls ie waiting until its ready, this should be used after navigation | |
| function Wait-For-IE{ | |
| while ($ie.Busy -eq $true -or $ie.Document -eq $null ) | |
| { | |
| Start-Sleep -seconds 1; | |
| write-host 'waiting for IE' | |
| } | |
| } | |
| function Click-Element($id){ | |
| $element = Get-Element $id | |
| $element.click() | |
| } | |
| function Get-Element($id){ | |
| return $ie.Document.getElementByID($id) | |
| } | |
| function Set-Element-Value($id,$eleVal){ | |
| $element = Get-Element($id) | |
| $element.value = $eleVal | |
| } | |
| #============================================================================================== | |
| $username='' | |
| $password='' | |
| $ie = New-Object -ComObject 'internetExplorer.Application' | |
| $ie.Visible= $true | |
| $ie.Navigate("http://localhost:51482//Account/Login") | |
| Wait-For-IE | |
| Sleep-UI | |
| Set-Element-Value 'UserName' $username | |
| Sleep-UI | |
| Set-Element-Value 'Password' $password | |
| Sleep-UI | |
| Click-Element 'btn-main-login' | |
| Wait-For-IE | |
| Sleep-UI | |
| Click-Element 'link-layout-lo-admin' | |
| Wait-For-IE | |
| Sleep-UI | |
| Click-Element 'link-add-new-listing' | |
| Wait-For-IE | |
| Sleep-UI | |
| Click-Element 'dropdown-select-roof-system' | |
| Sleep-UI | |
| $roofSelect = $ie.Document.getElementByID( 'dropdown-select-roof-system') | |
| $roofSelect.value = 1 #Single Ply | |
| Sleep-UI | |
| #there are multiple checkboxes with the same id | |
| $roofApplication = $ie.Document.getElementByID( 'RoofApplicationValues') | |
| $roofApplication.checked = 'checked' | |
| Sleep-UI | |
| Click-Element('AddPerformance') | |
| Wait-For-IE | |
| Sleep-UI | |
| $psfTextbox = $ie.Document.getElementByID( 'txt-wind-uplift-psf') | |
| $psfTextbox.value = (Get-Random -Minimum 100 -Maximum 400) | |
| Sleep-UI | |
| $roofApplication = $ie.Document.getElementByID( 'StandardVersionColl_0__StandardId') | |
| $roofApplication.checked = 'checked' | |
| Sleep-UI | |
| Click-Element 'AddDeck' | |
| Wait-For-IE | |
| Sleep-UI | |
| $deckDropDown = $ie.Document.getElementByID( 'DeckTypeId') | |
| $deckDropDown.value = 2 | |
| $deckDropDown.FireEvent('onchange') #need because JS submits the page on change LOL! that needs fixed | |
| Wait-For-IE | |
| Sleep-UI | |
| $deckPsiText = $ie.Document.getElementByID( 'psi') | |
| $deckPsiText.value = (Get-Random -Minimum 5 -Maximum 50) | |
| Sleep-UI | |
| Click-Element 'AddLayer' | |
| Wait-For-IE | |
| Sleep-UI | |
| Click-Element 'Yes' #Required Dialog | |
| Sleep-UI 1000 | |
| $productCategoryDropDown = $ie.Document.getElementByID('ProductCategoryId') | |
| $productCategoryDropDown.value = 4 #single ply membrane | |
| $productCategoryDropDown.FireEvent('onchange') | |
| Sleep-UI 1000 | |
| #the productcategoryId.onchange doesnt appear to be working at all, investigate why the deckDropDown JS handler works but this doesnt... | |
| #Ends |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment