Powershell: IE Web Form - Can't Identify Input Box's for entering data

0

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:

InputField

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

iframe1 iframe2

powershell
internet-explorer
webforms
asked on Stack Overflow Dec 14, 2018 by JGR • edited Dec 18, 2018 by JGR

2 Answers

2

You do not show the target URL, why? IS this an internal site, hence the sanitation?

You can walk the form fields directly using, say this approach...

$w = Invoke-WebRequest -Uri 'Some url'
$w.StatusCode
$w.AllElements
$w.Links
$w.Forms
$w.Forms[0].Fields
$w.RawContent
$w.ParsedHtml

Then once you have that, you can do your remaining use case.

answered on Stack Overflow Dec 14, 2018 by postanote
1

It looks like whatever backend for this website is dynamically generating these inputs and doesn't assign them a fixed name. Instead of looking directly for the element, I would suggest looking for the Parent Element and then searching for your elements under possible parent matches

So instead of looking for sys_display.IO:69c7ac57db7f7a00d7efb96c4e9619ae you can start by looking for <div class='input-group' and then searching for the <input> then matching the name to sys_display. You can also try and match ac_colums=email and the parent of <div class='input-group' which will help narrow the parameters you need to search.

*Fair warning, I've only done this with Selenium and not IE Webform... If possible, you might need to use XPath searching instead so you can match a Tag/Class/Name at the same time.

answered on Stack Overflow Dec 17, 2018 by Shadowzee

User contributions licensed under CC BY-SA 3.0