Powershell Parse HTML

Qlemo, if you can help with this it would be great!

Else anyone that wants to take a stab at it would be great!


At one time code below was fine but something changed at the password field now it displays the password on the field but its not actually really there. I also have screen shots at the bottom of post.

Here is the code.
<#	
	.NOTES
	===========================================================================
	 Created with: 	SAPIEN Technologies, Inc., PowerShell Studio 2014 v4.1.75
	 Created on:   	3/13/2015 2:24 AM
	 Created by:   	leandrot
	 Organization: 	
	 Filename:     	
	===========================================================================
	.DESCRIPTION
		A description of the file.
#>
if (!(Get-Variable ie -Scope global -ea SilentlyContinue) -or !$ie.Document)
{
	$global:ie = New-Object -comobject InternetExplorer.Application
}
$ie.visible = $true
$ie.silent = $true

$global:ReportPart = "/interface/folderTree.jsp?rootId=216&expandLevel=1&clearUIPath=true&uiPathLabel=Reports"
#                     /interface/folderTree.jsp?rootId=216&amp;expandLevel=1&amp;clearUIPath=true&amp;uiPathLabel=My+Reports    # sample Akebono Brake Corporation	UTA 6.1

function Test-ReportSite ([String] $url, [String] $login, [String] $password)
{
	$ie.Navigate2($url)
	while ($ie.busy) { Start-Sleep -m 100 }
	while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
	
	$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'loginField' } | % { $_.value = $login }
	$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'passwordField' } | % { $_.value = $password }
	$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'button' } | % { $_.Click() }
	while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
	
	$ie.Navigate2($url + $ReportPart)
	while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
	
	$link = $ie.Document.getElementsByTagName("a") | ? { $_.InnerText -like '*Overtime Report' } | select -First 1 -expandProperty href
	if (!$link)
	{
		$link = $ie.Document.getElementsByTagName("a") | ? { $_.InnerText -like '*Count' } | select -First 1 -expandProperty href
	}
	$ie.Navigate2($link)
	while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
	
	$ie.Document.getElementsByTagName("button") | ? { $_.innerText -eq 'Go' } | % { $_.Click() }
	Start-Sleep 5
	
<#  Error message evaluation ignored ATM   
  $ie.Document.getElementsByTagName("span") | ft -a classname, tagname, innerText #Gets you error
#>
	
	$RunByTest = $ie.Document.body.tagname -eq 'FRAMESET' -and $ie.Document.body.id -eq 'reportViewerFrame'
	
	if ($RunByTest)
	{
		$TestValue = 200
	}
	else
	{
		$TestValue = -200
	}
	Write-Host "$URL`: $TestValue"
	return $TestValue
}
                                          

Open in new window


Here is a screen shot of both runs.
Run on far left:
This run was done by script it actually placed the password in the field hence I had to conceal it. This attempts fails says bad password

Run on Far right:
This run was done manually entered the user name and pass word and it was a success so the password is correct.

I did notice the one has type="text" jQuery17109076306209054977="8" (This fails)

The other has type="password" jQuery17109076306209054977="7"  (This passes)

Sample
How do we change code to do the pass instead of the fail
LVL 8
Leo TorresSQL DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leo TorresSQL DeveloperAuthor Commented:
These  were my guess

#Change this line(Line 30 in code above)
$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'passwordField' } | % { $_.value = $password }

#To this line
$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'passwordField' -and $_.type -eq "password" } | % { $_.value = $password }

#or to this line
$ie.Document.getElementsByTagName("input") | ? { $_.name -eq 'password' -and $_.type -eq "password" } | % { $_.value = $password }

Open in new window


Neither changed worked. No error but nothing was entered in password field.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Why is the HTML code different? It is obvious that at the left the display field is called "passwordField", while at the right it is the input field ...
Please show the HTML part before the password is filled in by the PS script.
Leo TorresSQL DeveloperAuthor Commented:
Here is code and picture

UTA-Error-Doubleshot2.PNG
<HTML><HEAD><TITLE>UltiPro Time & Attendance - Login</TITLE>
<SCRIPT type=text/javascript>
	 window.name = 'wfm_top_window';
	 var wfm_top_window_flag = true;
	</SCRIPT>

<SCRIPT type=text/javascript src="/system/wfmupfront-142190041.js"></SCRIPT>

<META content=no-cache http-equiv=Pragma>
<SCRIPT type=text/javascript src="/js/jquery-142190041.js"></SCRIPT>

<SCRIPT type=text/javascript src="/js/jquery.ui-142190041.js"></SCRIPT>

<SCRIPT type=text/javascript src="/js/mod/jquery.ui.datepicker.mod-142190041.js"></SCRIPT>

<SCRIPT type=text/javascript src="/js/json-142190041.js"></SCRIPT>

<SCRIPT type=text/javascript src="/system/wbjquery-142190041.js"></SCRIPT>

<SCRIPT type=text/javascript src="/system/wbutil-142190041.js"></SCRIPT>

<SCRIPT type=text/javascript src="/system/wfm.common.widgets-142190041.js"></SCRIPT>

<SCRIPT type=text/javascript src="/system/wfm.common.initialization-142190041.js"></SCRIPT>

<SCRIPT type=text/javascript>var contextPath='';</SCRIPT>

<SCRIPT type=text/javascript>var contextURL=location.href.substring(0, location.href.indexOf('/', 8)) + contextPath;</SCRIPT>

<SCRIPT type=text/javascript>var formPath='/login.jsp';</SCRIPT>
<LINK rel=stylesheet type=text/css href="/infor.css"><LINK rel=stylesheet type=text/css href="/wbjquery.css"></HEAD>
<BODY class=login onload="if ( window.initializePage ) { initializePage(); }jumpToLastScrollPos();" bgColor=white>
<FORM onsubmit="return wbValidateForm();" method=post name=page_form action=/login.jsp autocomplete="off"><INPUT id=wbat type=hidden value=wtMvHEUaEF3IdWJJKvKPcDclyAKoPvu1 name=wbat> 
<DIV id=pageActionDiv style="PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 0px; PADDING-RIGHT: 0px"><INPUT type=hidden name=pageAction></DIV>
<DIV id=breadcrumb style="DISPLAY: none"></DIV>
<DIV id=pageStatusBox>
<DIV id=statusLeft class=statusLeft></DIV>
<DIV id=statusMessage class=statusMsg>
<UL id=list></UL></DIV>
<DIV id=statusRight class=statusRight></DIV></DIV>
<DIV id=centered><INPUT type=hidden value=-2144849815024229055 name=url_login_token> <!-- TT100603 - To work around <input type='placeholder'> for IE -->
<SCRIPT src="js/jquery.placeholder-142190041.js"></SCRIPT>

<SCRIPT type=text/javascript>
var isFormSubmitted = false;

document.onkeyup = checkValue

function checkValue(evt){
  if (!evt) {
    evt = window.event;
  }

  if (evt.keyCode == 13) {
    document.forms.page_form.pageAction.value='login';
    document.forms.page_form.submit();
  }
}
</SCRIPT>

<DIV tabIndex=-1 id=inforLoginWrappingDiv class=inforSignInDialog>
<DIV id=inforSignInDialog class="inforDialogContent inforoginConent"><!--<button class="inforModuleCloseButton" type="button" title="Cancel"></button>-->
<DIV class=inforLogoTm></DIV>
<P class=inforApplicationName>UltiPro Time &amp; Attendance</P>
<DIV class=inforSignInControls><INPUT id=loginField class=inforTextbox value=workbrain name=login jQuery17109076306209054977="6" placeholder="Login Id"> <INPUT id=passwordField class="inforTextbox placeholder" value=Removedpasswordhere jQuery17109076306209054977="8" placeholder="Password:"><INPUT class=inforTextbox style="DISPLAY: none" type=password value="" name=password jQuery17109076306209054977="7" placeholder="Password:"> 
<DIV class=inforSignInButtonSet><BUTTON id=submitButton class="inforFormButton default" jQuery17109076306209054977="5" isdefault="true" tooltip="Sign In">
<DIV class=arrow></DIV></BUTTON> </DIV><BR>
<DIV class=inforCheckboxContainer>
<DIV class=inforCheckbox><SPAN><SPAN class=inforCheckbox><INPUT id=changePassword class="inforCheckbox inforChangePassCheckBox inforTransparentCheckbox" type=checkbox name=password_change_requested jQuery17109076306209054977="1"></SPAN></SPAN> </DIV><LABEL class=inforCheckboxLabel for=changePassword data-localizedtext="RememberMe">Change Password</LABEL> </DIV></DIV>
<DIV class="inforClearBoth loginMsgArea"></DIV>
<DIV class="inforClearBoth inforETMPostion">
<DIV id=etm><INPUT onclick="window.location='/etm/login.jsp'" class="inforFormButton default" type=button value=ETM jQuery17109076306209054977="4" wbtitle="Switch to Employee Transaction Manager"></DIV></DIV></DIV></DIV></DIV>
<SCRIPT type=text/javascript>
setTimeout("document.forms[0].elements.login.focus();",100);

$(document).ready(function() {    
	$('#changePassword').change(function (){
	     $(this).parent().removeClass("checked");
	     if(this.checked)$(this).parent().addClass("checked");	
	});
	
	$('#submitButton').click(function (){
	    if( isFormSubmitted ) return;
		isFormSubmitted = true;
		document.forms.page_form.pageAction.value='login';
		document.forms.page_form.submit();
	});
	
	var $localeSelectWraper = $('.localeSelectWrapper');
		
		if( $('#clientShown').length == 1)$localeSelectWraper.removeClass("inforClearBoth"); 
		
		$localeSelectWraper.hover(
		  function() { $localeSelectWraper.addClass("localeSelectWrapperHover"); },
		  function() { $localeSelectWraper.removeClass("localeSelectWrapperHover"); }
		);
		
		var $localeSelect = $('.localeSelect');
		
		$localeSelect.focus( function() {
		   $localeSelectWraper.addClass('localeSelectWrapperFocus');
		});

		$localeSelect.blur( function() {
		  $localeSelectWraper.removeClass('localeSelectWrapperFocus');
		});
	
});
</SCRIPT>

<SCRIPT type=text/javascript>	
document.forms[0].autocomplete="off"
</SCRIPT>
<!-- TT100603 - To work around <input type='placeholder'> for IE -->
<SCRIPT type=text/javascript>
	$(function() {
		$('input').placeholder();
	});
</SCRIPT>

<SCRIPT type=text/javascript>	
document.forms[0].action='/login.jsp'
</SCRIPT>
<INPUT id=wbXpos type=hidden value=0 name=wbXpos> <INPUT id=wbYpos type=hidden value=0 name=wbYpos> </FORM>
<SCRIPT type=text/javascript>


 function getLocalizedMessage_INCORRECT_VALUE(){
     return "The value entered in the field is not correct.";
}


function initializePage() {


    if (insideWfmTopWindow()) {
	      parent.getWfmTopWindow().location = "/login.jsp?config=false&locale=EN";
    }

methodInitializePageFinished = true;
}
</SCRIPT>

<DIV id=inforTooltip class=inforTooltip style="DISPLAY: none" jQuery17109076306209054977="2">
<DIV class="arrow up"></DIV>
<DIV class=content></DIV>
<DIV class="arrow down"></DIV></DIV></BODY></HTML>

Open in new window

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
That is still after the password has been set (the original code).
But, as I see it, your second change should work:
$ie.Document.getElementsByTagName("input") | ? { $_.name -eq 'password' -and $_.type -eq "password" } | % { $_.value = $password }

Open in new window

Check if it finds something at all:
$ie.Document.getElementsByTagName("input") | ? { $_.name -eq 'password' -and $_.type -eq "password" }  | write-host
read-host

Open in new window

(The read-host is required if you are not able to debug and single-step the code).
Leo TorresSQL DeveloperAuthor Commented:
Well the Write-Host
Wrote this out to screen "System.__ComObject"

The read-host Prompted me for text. I entered the password there and it did nothing no password to field.
Leo TorresSQL DeveloperAuthor Commented:
Yes you would think my second line and your line would work but it does not. The one we need does not have "id" could that make suck a difference.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Sorry, I cannot see why it should not work. Probably something with the site code ... I cannot recommend anything else than to try and err, The test code gave a result, setting the result object value to the password should work.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Leo TorresSQL DeveloperAuthor Commented:
Sorry I didn't understand  " setting the result object value to the password should work."
Leo TorresSQL DeveloperAuthor Commented:
I just can understand why the Login field works but the password one does not

This is what the object looks likes

className                    : inforTextbox
id                           : 
tagName                      : INPUT
parentElement                : System.__ComObject
style                        : System.__ComObject
onhelp                       : 
onclick                      : 
ondblclick                   : 
onkeydown                    : 
onkeyup                      : 
onkeypress                   : 
onmouseout                   : 
onmouseover                  : 
onmousemove                  : 
onmousedown                  : 
onmouseup                    : 
document                     : mshtml.HTMLDocumentClass
title                        : 
language                     : 
onselectstart                : 
sourceIndex                  : 44
recordNumber                 : 
lang                         : 
offsetLeft                   : 226
offsetTop                    : 241
offsetWidth                  : 0
offsetHeight                 : 0
offsetParent                 : System.__ComObject
innerHTML                    : 
innerText                    : 
outerHTML                    : <INPUT class=inforTextbox style="DISPLAY: none" type=password value="" name=password jQuery171013334715260682256="7" placeholder="Password:">
outerText                    : 
parentTextEdit               : System.__ComObject
isTextEdit                   : True
filters                      : System.__ComObject
ondragstart                  : 
onbeforeupdate               : 
onafterupdate                : 
onerrorupdate                : 
onrowexit                    : 
onrowenter                   : 
ondatasetchanged             : 
ondataavailable              : 
ondatasetcomplete            : 
onfilterchange               : 
children                     : System.__ComObject
all                          : System.__ComObject
scopeName                    : HTML
onlosecapture                : 
onscroll                     : 
ondrag                       : 
ondragend                    : 
ondragenter                  : 
ondragover                   : 
ondragleave                  : 
ondrop                       : 
onbeforecut                  : 
oncut                        : 
onbeforecopy                 : 
oncopy                       : 
onbeforepaste                : 
onpaste                      : 
currentStyle                 : System.__ComObject
onpropertychange             : 
tabIndex                     : 0
accessKey                    : 
onblur                       : 
onfocus                      : 
onresize                     : 
clientHeight                 : 18
clientWidth                  : 143
clientTop                    : 1
clientLeft                   : 1
readyState                   : complete
onreadystatechange           : 
onrowsdelete                 : 
onrowsinserted               : 
oncellchange                 : 
dir                          : 
scrollHeight                 : 18
scrollWidth                  : 143
scrollTop                    : 0
scrollLeft                   : 0
oncontextmenu                : 
canHaveChildren              : False
runtimeStyle                 : System.__ComObject
behaviorUrns                 : System.__ComObject
tagUrn                       : 
onbeforeeditfocus            : 
isMultiLine                  : False
canHaveHTML                  : False
onlayoutcomplete             : 
onpage                       : 
onbeforedeactivate           : 
contentEditable              : inherit
isContentEditable            : True
hideFocus                    : False
disabled                     : False
isDisabled                   : False
onmove                       : 
oncontrolselect              : 
onresizestart                : 
onresizeend                  : 
onmovestart                  : 
onmoveend                    : 
onmouseenter                 : 
onmouseleave                 : 
onactivate                   : 
ondeactivate                 : 
onmousewheel                 : 
onbeforeactivate             : 
onfocusin                    : 
onfocusout                   : 
uniqueNumber                 : 6
uniqueID                     : ms__id6
nodeType                     : 1
parentNode                   : System.__ComObject
childNodes                   : System.__ComObject
attributes                   : System.__ComObject
nodeName                     : INPUT
nodeValue                    : 
firstChild                   : 
lastChild                    : 
previousSibling              : System.__ComObject
nextSibling                  : System.__ComObject
ownerDocument                : mshtml.HTMLDocumentClass
prefix                       : 
localName                    : 
namespaceURI                 : 
textContent                  : 
dataFld                      : 
dataSrc                      : 
dataFormatAs                 : 
role                         : 
ariaBusy                     : 
ariaChecked                  : 
ariaDisabled                 : 
ariaExpanded                 : 
ariaHaspopup                 : 
ariaHidden                   : 
ariaInvalid                  : 
ariaMultiselectable          : 
ariaPressed                  : 
ariaReadonly                 : 
ariaRequired                 : 
ariaSecret                   : 
ariaSelected                 : 
ie8_attributes               : 
ariaValuenow                 : 
ariaPosinset                 : 
ariaSetsize                  : 
ariaLevel                    : 
ariaValuemin                 : 
ariaValuemax                 : 
ariaControls                 : 
ariaDescribedby              : 
ariaFlowto                   : 
ariaLabelledby               : 
ariaActivedescendant         : 
ariaOwns                     : 
ariaLive                     : 
ariaRelevant                 : 
ie9_tagName                  : 
ie9_nodeName                 : 
onabort                      : 
oncanplay                    : 
oncanplaythrough             : 
onchange                     : 
ondurationchange             : 
onemptied                    : 
onended                      : 
onerror                      : 
oninput                      : 
onload                       : 
onloadeddata                 : 
onloadedmetadata             : 
onloadstart                  : 
onpause                      : 
onplay                       : 
onplaying                    : 
onprogress                   : 
onratechange                 : 
onreset                      : 
onseeked                     : 
onseeking                    : 
onselect                     : 
onstalled                    : 
onsubmit                     : 
onsuspend                    : 
ontimeupdate                 : 
onvolumechange               : 
onwaiting                    : 
constructor                  : 
onmspointerdown              : 
onmspointermove              : 
onmspointerup                : 
onmspointerover              : 
onmspointerout               : 
onmspointercancel            : 
onmspointerhover             : 
onmslostpointercapture       : 
onmsgotpointercapture        : 
onmsgesturestart             : 
onmsgesturechange            : 
onmsgestureend               : 
onmsgesturehold              : 
onmsgesturetap               : 
onmsgesturedoubletap         : 
onmsinertiastart             : 
onmstransitionstart          : 
onmstransitionend            : 
onmsanimationstart           : 
onmsanimationend             : 
onmsanimationiteration       : 
oninvalid                    : 
xmsAcceleratorKey            : 
spellcheck                   : False
onmsmanipulationstatechanged : 
oncuechange                  : 
type                         : password
value                        : 
name                         : password
status                       : False
form                         : System.__ComObject
size                         : 20
maxLength                    : 2147483647
defaultValue                 : 
readOnly                     : False
indeterminate                : False
defaultChecked               : False
checked                      : False
border                       : 
vspace                       : 0
hspace                       : 0
alt                          : 
src                          : 
lowsrc                       : 
vrml                         : 
dynsrc                       : 
complete                     : False
loop                         : 1
align                        : 
width                        : 0
height                       : 0
start                        : fileopen
accept                       : 
useMap                       : 
selectionStart               : 
selectionEnd                 : 
ie8_src                      : 
ie8_lowsrc                   : 
ie8_vrml                     : 
ie8_dynsrc                   : 
min                          : 
max                          : 
step                         : 
valueAsNumber                : 

Open in new window


Your write host wrote "System.__ComObject" are we assign password to wrong item?
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The password field is built by two different fields in fact, to hide the real input. Password fields can get tricky to fill by software because of that.

"setting the result object ..." refers to exactly this code line:
$ie.Document.getElementsByTagName("input") | ? { $_.name -eq 'password' -and $_.type -eq "password" } | % { $_.value = $password }

Open in new window

The test code showed you get a COM object. Setting its value should result in the password field getting set. There is nothing more I can say - you'll have to try yourself again, and fiddle around with both password fields. Maybe you need to set both instead of one only?
Leo TorresSQL DeveloperAuthor Commented:
Good point on setting both. I will try that. I am looking for items in Powershell debug mode. will see if I can provide news thanks again for help.
Leo TorresSQL DeveloperAuthor Commented:
Here is something interesting that may help.

The image below shows code in debug mode while watching variables in question. Login field got set as workbrain, the password field receives its sample display value. The last variable should be blank value not empty my guess. My feeling about empty means this value does not exists because it cant find a name and type "password" string match. Thats why I think no value is being set. I ran thru highlighted line 34 times before it got to where its at now. Will continue to step thru see what happens will post more thoughts here soon.

samplesample
Leo TorresSQL DeveloperAuthor Commented:
thanks
Leo TorresSQL DeveloperAuthor Commented:
New thread
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28636421.html

Just need IE to close and open for every link passed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.