I'm trying to fill out some text input/drop-down boxes in IE with a PowerShell (PoSH) script, and I've been using examples provided on the Internet, including here, and here.
However, I haven't been able to get or identify the text boxes via GetElementsByTagName()
- I think it acts like they're not populating in the variable. I'm not sure what's going on, I've been looking around on the internet (Google searches), but haven't seen anything that says there's more to it than just these few lines of code.
Code and pictures, as well as error to follow:
$url = "[webPage]";
#initialize browser
$ie = New-Object -Com InternetExplorer.Application;
$ie.Visible = $true;
$ie.ParsedHTML;
$ie.Navigate($url);
while ($ie.busy) {Start-Sleep 4}
#get form
$doc = $ie.Document;
$form = $doc.Forms[0];
$inputs = $form.GetElementsByTagName("input");
#fill out form fields
#either this:
$ie.Document.GetElementByID("sys_display.IO:69c7ac57db7f7a00d7efb96c4e9619ae").Value = "Jonathan Rotter"
#or this:
($inputs | where {$_.Name -eq "sys_display.IO:69c7ac57db7f7a00d7efb96c4e9619ae"}).Value = "Test"
I've tried adding the following to the top of this (from here), but no change:
[void][System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
I can see the ID/Name/(Tag-Name??) in the page:
I've entered the PoSH script line-by-line (to make sure the web-page loaded properly) and checked on the output, and (as an example), the following line results in this error message:
($inputs | where {$_.Name -eq "sys_display.IO:69c7ac57db7f7a00d7efb96c4e9619ae"}).Value = "Test"
The property 'value' cannot be found on this object. Verify that the
property exists and can be set. At line:1 char:1
+ ($inputs | where {$_.name -eq "sys_display.IO:69c7ac57db7f7a00d7efb96 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
After running all the steps, these two lines show the following:
PS> $inputs | Select-Object Type,Name
type name
---- ----
hidden sysparm_ck
search sysparm_search
PS> $doc.IHTMLDocument3_getElementsByTagName("input") | Select-Object Type,Name
type name
---- ----
hidden sysparm_ck
search sysparm_search
checkbox 843.8919931998148glide_ui_accessibility
checkbox 265.6701858983173glide_ui_compact
checkbox 689.5920854347255glide_ui_short_date_format
radio 884.3975056898055my_home_navigation_page
radio 884.3975056898055my_home_navigation_page
radio 38.12548394764709glide_ui_date_format
radio 38.12548394764709glide_ui_date_format
radio 38.12548394764709glide_ui_date_format
radio theme
radio theme
radio theme
radio theme
radio theme
radio theme
radio theme
radio theme
checkbox 246.5551307536581table_wrap
checkbox 498.31620519246865tabbed_forms
radio 436.6892116346038glide_ui_related_list_t...
radio 436.6892116346038glide_ui_related_list_t...
radio 436.6892116346038glide_ui_related_list_t...
checkbox 693.6896755526656connect_notifications_m...
checkbox 68.17405211392419connect_notifications_d...
checkbox 958.4840125981943connect_notifications_e...
checkbox 276.20029685304047connect_notifications_...
hidden sysparm_ck
search filter
search leftSearch
search
Please help point me somewhere for a next step, I'm not sure what I'm missing.
Edit 20181218 It looks like the fields I need are inside an "iframe." I'm still struggling with drilling down into it with code, and have been playing with this line found Here, but I'm still not sure how to get to it (adjusted for my web-page with the above code):
$form=$doc.frames.document.forms
Gives me more stuff to look at, but this errors changed this:
PS U:\> $ie.document.getElementByID("gsft_main")
Exception from HRESULT: 0x800A01B6
To this and looking some more:
$frame=$ie.document.IHTMLDocument3_getElementByID("gsft_main")
Images from inspection (F11):