I'm trying to automate a simple web form login and capture the output and values from elements on a page using PowerShell (using getElementById/TagName
).
I know there are examples of people using the InternetExplorer.Application
COM object, but I know .net comes with the System.Windows.Forms.WebBrowser
object.
My questions are - is it possible to do this UI Automation with just .net objects by loading WebBrowser object in memory and have it navigate to my URL then run my logic after navigation is complete? Does this object need to be added to a Windows form before it begins to do any processing?
Here's what I'm somewhat trying to do:
[void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$browser = New-Object System.Windows.Forms.WebBrowser
$browser.Navigate("http://somesite.net/loginPage")
do {
Start-Sleep -Seconds 1
}until($browser.ReadyState -eq 'complete')
$txtUsername = $browser.Document.getElementsByTagName('txtuser')
$txtPassword = $browser.Document.getElementsByTagName('txtpass')
# Perform more stuff here