Trying to extend Jay's scripts - Article ID: W16783

Started by George Vagenas, November 06, 2013, 06:10:48 PM

Previous topic - Next topic

George Vagenas

I've been running a script based on This TechDB article for many years.  I've used it personally  and for clients who needed this functionality.  Recently, in trying to revise my daughter's bookkeeping spreadsheets, I once again found a use for this utility.

Currently the script logs on to her bank account and downloads various account pages (html), extracts the relevant data from the pages and loads them into her spreadsheets.  The problem is that the pages are always being revised which requires a rewrite of the script.  Sometimes the changes are minor others times it involves a significant amount of work to just figure out what changed and how to fix it.  My apologies for length of this preamble but it is relevant to what I'm trying to accomplish.

While the underlying pages of the banks website are frequently changed its functionality does not.  What I'm trying to do is access the csv files that have always been available from the site.  If I can revise the script to do this its bye bye page scrapping and an easy step to import the data into Excel.  So here's the current code:
Code (winbatch) Select
   prqType       = prqAll.OptionFilterNameValue
   prqType.value = 'ALL'     
   
   prqType       = prqAll.getAccountActivity
   
   if !prqNewPage('GetStmtAction', 'VerifyActivityHdr')
      gErr = 'ACCOUNTNOTAVAILABLE'
      return
   endif

which grabs the raw pages for processing.  But at this point the script is logged onto the webpage which has a clickable label "Advanced Options" which opens up two selection controls, one defaults to grab everything which is what I want and the other has an option to "Download to Comma Delimited Text".  When I look at the page source this is the relevant line
Code (html5) Select
</div>
  </div>
<div class="hr"><hr/></div>
<h3>
<span class="showHideSwitch11 icon unselected"><a href="#">Advanced Options</a></span>
</h3>
<div class="showHide11">

<div class="entry entryInline">



<label for="OptionFilterNameValue" title="Select transaction type">
Show
</label>
<div class="input">



And here's the IE formated source
Code (html5) Select
</DIV></DIV><DIV class="SYN_ROW"><DIV class="SYN_LNB">
<INPUT type="label" value="981" unselectable="on" class="SYN_LNN">
<INPUT role="button" type="label" value="-" unselectable="on" id="syn_ctrl981" class="SYN_BCH">
</DIV><DIV class="SYN_TXT" style="padding-left:1em;text-indent:-0.5em" id="syn_row981">
<SPAN class="HTML_TXT">
<SPAN class="HTML_TAG">&lt;<SPAN class="HTML_ELM">span</SPAN>
<SPAN class="HTML_ATR">class</SPAN>=
<SPAN class="HTML_VAL">"showHideSwitch11 icon unselected"</SPAN>&gt;</SPAN>
<SPAN class="HTML_TAG">&lt;<SPAN class="HTML_ELM">a</SPAN>
<SPAN class="HTML_ATR">href</SPAN>=<SPAN class="HTML_VAL">"#"</SPAN>&gt;</SPAN>Advanced Options
<SPAN class="HTML_TAG">&lt;/<SPAN class="HTML_ELM">a</SPAN>&gt;</SPAN>
<SPAN class="HTML_TAG">&lt;/<SPAN class="HTML_ELM">span</SPAN>&gt;</SPAN></SPAN>
Its one long line in the file but I've broken it up to make it easier to read.
I've tried every variation I can think of to try and access this input here's a sample
Code (winbatch) Select
   prqType       = prqAll.getAccountActivity

      ;debug(1) ;***DEBUG LINE***
breakpoint
prqType = prqAll.input
prqType = prqAll.name
prqType.value = "srchvalue"
; prqType = prqObj.label
; prqType = prqAll.stype
; prqType.value =  "Advanced Options"
prqType.click   
      ;debug(1) ;***DEBUG LINE***
   
   if !prqNewPage('GetStmtAction', 'VerifyActivityHdr')
      gErr = 'ACCOUNTNOTAVAILABLE'
      return
   endif

I'm stumped, if anyone could offer a fix I'd really appreciate it.
Thanks

George

Deana

A few questions:

How is the prqAll variable defined?
Are you able to successfully get a handle to the button element you would like to click on? If so maybe try something like this to click on the button:

Code (winbatch) Select

; Unfortunately .Click method doesn't work on IE 9 or newer.
; However this method seems to work:
; Reference: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/OLE~with~MSIE+IE9~Click~or~Focus~Methods~Fail.txt
objBtn = form.GetElementsByTagName("INPUT").Item(1) ;Use your code here to obtain the object to click on
objEvent = browser.document.createEvent("HTMLEvents")
objEvent.initEvent("click", @TRUE, @TRUE)
objBtn.dispatchEvent(objEvent)


Also this thread looks interesting since you are dealing with Labels...
http://forums.asp.net/t/1313311.aspx
Deana F.
Technical Support
Wilson WindowWare Inc.

George Vagenas

Thanks Deana but after thinking about it some more I realized I don't need to click the label/button.  I'm just trying to access the select control and the script can see it regardless of whether its visible to a user in the browser.  I may need some help distinguishing between the two submit buttons on the page, one submit the query the other returns to the site home page.
Thanks

George

George Vagenas

I was able to access the select control as I expected, unfortunately I was also right about probably needing help with the buttons.  I've tried numerous approaches to getting a handle to the second button on the form but I always manage to click the logout button. 
Here's the two button in question
Code (html5) Select
<div class="formActions">
<ul>
<li>
<input type="submit" title="Search Account Activity" id="getAccountActivity" value="Search">
</li>
</ul>
</div>
</div>
<form class="portlet authentication in contentlogin" id="PortletAuthentication" action="/Personal/" method="post">
<div class="hiddenInputs">
    <input type="hidden" class="hidden" name="LOGON" value="LOGOFF"/>
</div>
<h3>
George Vagenas

</h3>
<input type="submit" class="submit" name="submit" value="Logout of Online Banking"/>
</form>
Just one click away from a solution but I'm stumped. (Html really isn't my thing)
Thanks

George

Deana

Quote from: George Vagenas on November 07, 2013, 08:39:23 PM
I was able to access the select control as I expected, unfortunately I was also right about probably needing help with the buttons.  I've tried numerous approaches to getting a handle to the second button on the form but I always manage to click the logout button. 
Here's the two button in question
Code (html5) Select
<div class="formActions">
<ul>
<li>
<input type="submit" title="Search Account Activity" id="getAccountActivity" value="Search">
</li>
</ul>
</div>
</div>
<form class="portlet authentication in contentlogin" id="PortletAuthentication" action="/Personal/" method="post">
<div class="hiddenInputs">
    <input type="hidden" class="hidden" name="LOGON" value="LOGOFF"/>
</div>
<h3>
George Vagenas

</h3>
<input type="submit" class="submit" name="submit" value="Logout of Online Banking"/>
</form>
Just one click away from a solution but I'm stumped. (Html really isn't my thing)

I form can only contain one submit button.You can use the Form id="PortletAuthentication" to first reference the form then call the Submit method for that form:

Code (winbatch) Select
; Reference the Form by ID
oForm = oDoc.getElementById("PortletAuthentication")
; Submit that form
oForm.Submit()
Deana F.
Technical Support
Wilson WindowWare Inc.

George Vagenas

Thanks!!!
My confusion, it was the "getAccountActivity" button I wanted to click but your code did the trick.
Code (winbatch) Select
prqSubmit = prqDoc.getElementById('getAccountActivity')
prqSubmit.click

Hopefully, that's the last hurdle in this revision.  I'll probably replace the HTML forms with Dialogs (I did say I've been using this utility for years!) and convert the called wbt files to subroutines. 
Thanks

George