I am working on a script to automate filling out a ticketing system in IE. Typically for web browser automation I turn to AutoIt, but thought I would try if I could do this purely through PowerShell. Creating the page and navigating to it works just fine:
$screen = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
$oIE = New-Object -ComObject "InternetExplorer.Application" -ErrorAction Stop
$oIE.width = $screen.width
$oIE.height = $screen.height
$oIE.Top = 0
$oIE.Left = 0
$oIE.Visible = $true
$oIE.Silent = $true
$oIE.Navigate("myURL")
{
Start-Sleep -Milliseconds 1000;
}
I am unable, however, to pull the fields from the form. I tried something like this to get the main form:
$oCol = $oIE.document.forms.item("mainForm")
but no joy (I tried in AutoIt, and it works fine, so not sure why I can’t in PowerShell). Also tried just getting the element by ID, like so (using a description field as example):
$oIE.document.getElementsByTagName("input") | % {
if ($_.id -ne $null){
if ($_.id.Contains("Title4")) {
"Found it"
}
}
}
Based on the html line:
input type=‘text’ id=‘mainForm-Title4’ name=‘Title’ value=‘’
But I get “You cannot call a method on a null expression” on the getElementsByTagName call.
Even something so simple as trying to get the $oIE.Document doesn’t work. Just hoping someone can point out what I am obviously doing wrong.