VbScript to FWH translation ( login to a website follow up )

Post Reply
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

VbScript to FWH translation ( login to a website follow up )

Post by Rick Lipkin »

To All

I have been working on a Vbscript to login to a website, pass a login and click a submit button. I have successfully completed a working script I now wish to translate to xHarbour and FWH.

Here is the Vbscript code .. I have searched the forum and see where you can use active x and James posted some code to my above previous thread .. my problem now is to be able to navigate the site using the DOM id's or name of the fields I wish to populate .. logins and searches for parts .. etc

Any help would be appreciated.

Thanks
Rick Lipkin

Code: Select all

Option Explicit

Dim IE, WshShell
Set IE = CreateObject("InternetExplorer.Application")


With IE
  .Visible = True
  .Navigate "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1253879194&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1033&id=64855&mkt=en-us"
  Do While .Busy
    WScript.Sleep 200
  
  Loop
  
  ' use the web page dom names to fill in the proper fields

  .Document.getElementsByName("login").Item(0).Value = "myuserid"
  .Document.getElementsByName("passwd").Item(0).Value = "mypassword" 
  wscript.sleep (100)
 
  ' set up the submit button click 

  set WshShell = WScript.CreateObject("WScript.Shell")
  wscript.sleep (100)
  WshShell.SendKeys "{Enter}"

End With
 
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: VbScript to FWH translation ( login to a website follow up )

Post by lailton.webmaster »

Code: Select all

#include "FiveWin.ch"

Function Main()
LOcal IE, WshShell

IE       := CreateObject("InternetExplorer.Application")
WshShell := CreateObject("WScript.Shell")

IE:Visible := .t.
IE:Navigate( "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1253879194&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1033&id=64855&mkt=en-us" )
While IE:Busy
      WshShell :Sleep( 200 )
      SysRefresh() // To Refresh
      Loop
End
WshShell:sleep( 100 )
WshShell:SendKeys "{Enter}"

Return Nil
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: VbScript to FWH translation ( login to a website follow up )

Post by Rick Lipkin »

Lailton

Thank you for your reply .. and your code works with the following modifications to insert my credentials into the DOM fields 'login' and 'passwd' ..

However, once I get the automated login .. the page changes to my e-mail and I want to insert some 'text' into the search which has a DOM name of 'query'.

I realize the IE page and IE object has now changed and as you see I have attempted a EI:Refresh() .. but that does not seem to refresh the object holding the DOM .. and when I reference the search ( dom name is 'query' ) I get a run-time error on line 31 class: NIL meaning the dom name I am referencing does not exist ( see screen shot of the DOM )

Any help here would be appreciated.

Thanks
Rick Lipkin

Image

Image

Code: Select all

#include "fivewin.ch"

//--------------------------

Func Main()
Local IE, WshShell

IE       := CreateObject("InternetExplorer.Application")
WshShell := CreateObject("WScript.Shell")

IE:Visible := .t.
IE:Navigate( "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1253879194&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1033&id=64855&mkt=en-us" )

Do While IE:Busy
   SysWait(5)
   SysRefresh() // To Refresh
   Loop
Enddo

IE:Document:getElementsByName("login"):Item(0):Value = "*******@live.com"
IE:Document:getElementsByName("passwd"):Item(0):Value = "********"

SysWait(2)
WshShell:SendKeys( "{Enter}" )
SysWait(10)

IE:Refresh()
SysRefresh()
SysWait(3)

IE:Document:getElementsByName("query"):Item(0):Value = "rick"

Syswait(2)
WshShell:SendKeys( "{Enter}" )


Return Nil
 

Code: Select all

Application
===========
   Path and name: C:\Fox\WebCrawl\Hotmail.Exe (32 bits)
   Size: 1,873,920 bytes
   Time from start: 0 hours 0 mins 25 secs 
   Error occurred at: 04/27/11, 10:20:24
   Error description: Error BASE/1005  Class: 'NIL' has no property: VALUE
   Args:
     [   1] = U   
     [   2] = C   rick

Stack Calls
===========
   Called from:  => _VALUE(0)
   Called from: main1.prg => MAIN(31)
 
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: VbScript to FWH translation ( login to a website follow up )

Post by lailton.webmaster »

Try this way

Code: Select all

Try
 IE:Document:getElementsByName("UIFrame"):contentWindow:document: ( way frame and form here ) :getElementsByName("fieldname"):Item(0):Value = "rick"
Catch
 MsgInfo("It's Fail ...")
End
 
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: VbScript to FWH translation ( login to a website follow up )

Post by Rick Lipkin »

Lailton

You mentioned ( way frame and form ) .. I guess you meant the entire UIFrame line in the DOM inspector .. hi-lited in the screen shot and in the code below ?

If so .. the code did not work see the following error... did I not interpret your suggestion correctly ?

Thanks
Rick Lipkin
Try
IE:Document:getElementsByName("UIFrame"):contentWindow:document: ( way frame and form here ) :getElementsByName("fieldname"):Item(0):Value = "rick"
Catch
MsgInfo("It's Fail ...")
End

Code: Select all

#include "fivewin.ch"

//--------------------------

Func Main()
Local IE, WshShell

IE       := CreateObject("InternetExplorer.Application")
WshShell := CreateObject("WScript.Shell")

IE:Visible := .t.
IE:Navigate( "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1253879194&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1033&id=64855&mkt=en-us" )

Do While IE:Busy
   SysWait(5)
   SysRefresh() // To Refresh
   Loop
Enddo

IE:Document:getElementsByName("login"):Item(0):Value = "r2.1955@live.com"
IE:Document:getElementsByName("passwd"):Item(0):Value = "nov@1955"

SysWait(2)
WshShell:SendKeys( "{Enter}" )
SysWait(10)

*TRY       // failed also with getElementById
   IE:document:getElementsByName("UIFrame"):contentWindow:document:;
   forms:aspnetForm:c_search_psb_box:getElementsByName("query"):;
   Item(0):Value = "rick"
*CATCH
 *  MsgInfo("It Failed ...")
*END TRY

Syswait(2)
*WshShell:SendKeys( "{Enter}" )


Return Nil
 

Code: Select all

Application
===========
   Path and name: C:\Fox\WebCrawl\Hotmail.Exe (32 bits)
   Size: 1,873,920 bytes
   Time from start: 0 hours 0 mins 21 secs 
   Error occurred at: 04/27/11, 13:07:37
   Error description: Error InternetExplorer.Application:DOCUMENT:GETELEMENTSBYNAME/0  S_OK: CONTENTWINDOW
   Args:

Stack Calls
===========
   Called from: source\rtl\win32ole.prg => TOLEAUTO:CONTENTWINDOW(0)
   Called from: main1.prg => MAIN(30)
 
Image
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: VbScript to FWH translation ( login to a website follow up )

Post by lailton.webmaster »

How you see. the search of Live.com is a FRAME, so you need set value to object inside of frame. and not set to 'query'.

you need get object inside of frame to set value. and later send a submit to form inside of frame.
:)
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: VbScript to FWH translation ( login to a website follow up )

Post by Rick Lipkin »

Lailton

I appreciate your help and advice .. I was able to get the DOM inside the search field and I tried it with the entire line including the iframe as well as just the id without success ..

Included is the DOM of the frame and the second is the DOM of the inside of the frame .. any ideas on what I should reference in my code .. as you can see I have tried several DOM strings ?

Rick Lipkin

Code: Select all

#include "fivewin.ch"

//--------------------------

Func Main()
Local IE, WshShell

IE       := CreateObject("InternetExplorer.Application")
WshShell := CreateObject("WScript.Shell")

IE:Visible := .t.
IE:Navigate( "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1253879194&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1033&id=64855&mkt=en-us" )

Do While IE:Busy
   SysWait(5)
   SysRefresh() // To Refresh
   Loop
Enddo

IE:Document:getElementsByName("login"):Item(0):Value = "******@live.com"
IE:Document:getElementsByName("passwd"):Item(0):Value = "*******"

SysWait(2)
WshShell:SendKeys( "{Enter}" )
SysWait(10)

*TRY
*IE:document:frames:UIFrame:getElementById("c_search_psb_f"):;
* Item(0):Value = "rick"

IE:document:getElementById("UIFrame"):contentWindow:document:;
   getElementById("c_search_psb_f"):Item(0):Value = "rick"

*IE:document:getElementById("c_search_psb_f"):Item(0):Value = "rick"

    * IE:document:getElementById("UIFrame"):contentWindow:document:;
    * getElementById("c_search_psb_f"):Item(0):Value = "rick"

*CATCH
*   MsgInfo("It Failed ...")
*END TRY

Syswait(2)
*WshShell:SendKeys( "{Enter}" )


Return Nil
 
Image

Image
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: VbScript to FWH translation ( login to a website follow up )

Post by lailton.webmaster »

I'll do test and report my result for you.

Cya.
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: VbScript to FWH translation ( login to a website follow up )

Post by Rick Lipkin »

Lailton

Thank you for your help .. I am thinking it might be a refresh issue with the IE object .. As the page changes perhaps the IE object needs to be refreshed somehow so the DOM can be addressed correctly.

Rick Lipkin
r1.1955@live.com
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: VbScript to FWH translation ( login to a website follow up )

Post by lailton.webmaster »

Rick,

What you want do ? a outlook ? :D
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: VbScript to FWH translation ( login to a website follow up )

Post by Rick Lipkin »

Lailton

What I am ultimately trying to accomplish is to be able to login to a part vendors website and search for an item and return the results.

The first part of that is almost done .. I am just having problems with the DOM object ID which you should be able to reference by GetElementByID as in this code .. however, I can never seem to get that method to work either for a field or a control ..

Code: Select all

//----------------------------
Static Func Ebay()
Local IE, WshShell, fields, button

IE       := CreateObject("InternetExplorer.Application")
WshShell := CreateObject("WScript.Shell")

IE:Visible := .t.
IE:Navigate( "http://www.ebay.com/" )

Do While IE:Busy
   SysWait(1)
   SysRefresh() // To Refresh
   Loop
Enddo

buttons := nil
fields  := nil

fields  := IE:Document:getElementsByName("_nkw")
buttons := IE:Document:getElementById("ghSearch")

try
   fields[0]:value = "HMDX-GO"
   SysReFresh()
catch
   Msginfo("Could not find DOM element '_nkw'")
   IE:Quit()
   return(nil)
end try

try
   buttons[0]:click()
   SysReFresh()
catch
   Msginfo("Could not find DOM element 'ghSearch'")
   IE:Quit()
   return(nil)
end try

SysWait(2)

// use this to force an enter key for search button
*WshShell:SendKeys( "{Enter}" )

Return Nil
 
In the above example the id ghSearch is in the DOM .. but the GetElementByID method fails and I have had to resort to the work around by forcing a keystroke

// use this to force an enter key for search button
*WshShell:SendKeys( "{Enter}" )

to activate the search button control ..

Image

Image


It seams with all my tests with various websites including BestBuy .. even the GetElementByName for button controls either fail or do not work as in this example

Code: Select all

Static Func BestBuy()
Local IE, WshShell,field1,buttons

IE       := CreateObject("InternetExplorer.Application")
WshShell := CreateObject("WScript.Shell")

IE:Visible := .t.
IE:Navigate( "http://www.bestbuy.com/" )

Do While IE:Busy
   SysWait(1)
   SysRefresh() // To Refresh
   Loop
Enddo

field1  := ie:document:getelementsbyname("st")
buttons := ie:document:getelementsbyname("goButton")

try
   field1[0]:value = "computers"
   SysReFresh()
catch
   Msginfo("Could not find DOM element 'st'")
   IE:Quit()
   return(nil)
end try

try
   buttons[0]:click()
   SysReFresh()
catch
   Msginfo("Could not find DOM element 'goButton'")
   IE:Quit()
   return(nil)
end try


SysWait(2)
//WshShell:SendKeys( "{Enter}" )

Return Nil
 
Image

Feel free to cut, paste and compile the above examples and you can test the results for yourself ..

Any advice or help would be appreciated.

Rick Lipkin
r1.1955@live.com
Post Reply