IE: From Filling

Started by hdsouza, March 14, 2014, 06:59:05 AM

Previous topic - Next topic

hdsouza

I am attempting to fill in my login information on the IE page, but somehow I cannot figure out the Email/password boxes. they appear to be in a frame.
Please help


GoSub GetMSIE
Login = "dodo@gmail.com"
password = "dodo"

msie.document.Frames(0).GetElementByid("UserName").value = Login
msie.document.Frames(0).GetElementByid("Password").value = password
msie.document.GetElementByid("LoginButton").click

Exit

:GetMSIE
   Shell = ObjectOpen("Shell.Application")
   For x = 0 To Shell.Windows.count-1
      swc = Shell.Windows.count-1
      ErrorMode(@OFF)
      swi = Shell.Windows.item(x)
      If !swi
         ErrorMode(@CANCEL)
         Continue
      EndIf
      swif =  Shell.Windows.item(x).fullname
      If !StrIndexNC(swif, "iexplore.exe", 1, @FWDSCAN)
         ErrorMode(@CANCEL)
         Continue
      EndIf

      msie=Shell.Windows.item(x)
      URL = msie.LocationURL
      URL_Valid = StrIndexNC(URL, "invest", 1, @FWDSCAN)
      If !URL_Valid
         ErrorMode(@CANCEL)
         Continue
      Else
         Break
      EndIf
      ErrorMode(@CANCEL)
   Next
Return

td

One guess would be to try firing the 'Sign In' button to trigger the Java script that creates the frame.  You could possibly use the 'Frames' property of the document object to get the correct 'Frame' object and its 'Document' object.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hdsouza

How do you get 'Frames' property of the document object to get the correct 'Frame' object and its 'Document' object?
Or waht is the syntax I would need to use to get the frame for this webpage?

td

What a morning.  My "friends" at MSFT decided to install a hyper-critical-update on my workstation even though I have Windows Update set to notify only.  The update failed and made a mess of the OS..."One of these days, Alice. One of these days."

Anyway,  DOM frames are covered in the Tech Database so you can find your answer with a quick search on "frames" or "iFrames". 

I think your bigger problem is how to automate forcing the site to display the login prompt in the first place.  I wrote a quick script to test clicking the "signInOut-signIn2" list item which should trigger the java script that creates the login frame. However, none of the usual suspects seems to work.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

George Vagenas

Depending on what you're trying to do you log, on I use the following to automate Firefox to get pages from a couple of sites.
Code (winbatch) Select
   ; IF THE SCRIPT STOPS WORKING REVISIT THE SITE() WITH INTERNET EXPLORER.
   if Ask
      SrvrName = 'F00Site1'
      Srvr = 'http://www.F00Site1.net'
      Ok = iCookieGet(Srvr)
      If Ok==''
         Message('F00Site1 logon Error!', iGetLastError())
         Exit
      EndIf
   else
      SrvrName = 'F00Site2'
      Srvr = 'http://www.F00Site2.com'
      Ok = iCookieGet(Srvr)
      If Ok==''
         Message('F00Site2 logon Error!', iGetLastError())
         Exit
      EndIf
   endif
   
   boxopen('Getting pages from %SrvrName%', '')

iCookieGet(Srvr) works if the site has an option to remember your logon.
Thanks

George

hdsouza

George, I am not sure I undertstand what you have specified. I need a way to navigate a iFrame in IE. The login/password boxes are stored in an Iframe.  See original post

stanl

Quote from: hdsouza on March 14, 2014, 10:38:07 AM
How do you get 'Frames' property of the document object to get the correct 'Frame' object and its 'Document' object?
Or waht is the syntax I would need to use to get the frame for this webpage?

You need to check if the site uses JQuery. Often login prompts are really hidden DIV's. 

hdsouza

Guys, I think we going off topic here. All I need is a syntax to navigate to an element in an Iframe.

Is it similar to:
msie.document.Frames(0).GetElementByid("UserName").value = Login
or do i need to specify the id of iframe somewhere in the line above
The iframe id in this case is "easyXDM_default8377_provider"
or a combination

td

That frame does not exist on the default page.  At least it doesn't exist without a "remember me" cookie set.  If it does exist when you do have a cookie then do as previously suggested and use the example in the Tech. Database as a tutorial on inspecting frames by name.

Here is a link to one of the several examples.

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/OLE~with~MSIE+Dealing~with~iFrames.txt
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hdsouza

TD, I have used that example since you provided it to me this morning and have been able to idetify the Frame id and Frame_url
Frame_id = "easyXDM_default8377_provider"
Within the Frame_url are located the login/password boxes
I believe the objective now is: how do we get a handle to the items in the frame from the main page as the login button does not exist is the Iframe (but it exists on the main page)

td

Assuming you are using a recent version of IE or you have another browser handy,  fire up the browser's development tool (F12 for IE) and inspect the elements.  This should give you the name/ID of your target.  The tricky part may be getting the element's event to fire once you have the target in hand. This is particularly so for the latest and greatest versions of IE.

FWIIW, after working on it off and on all day, I have finally gotten my system wrenched from the evil clutches of our friends in Redmond.  IE even works again. Although that may not be a good thing.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hdsouza

TD, Good to hear that you up and running again
Yes I am able to see the elements of the Iframe page  that i need to get a handle to.
They are as in my initial post
Username_field = UserName
password_field = Password
But I believe I have to access thse elements from the main page as the Iframe page does not have signin button
OR
How would you suggest I get a handle to these elements in a way I can login to the page
Thanks

hdsouza

TD, I was able to send keystrokes into the iframe element and get it to work although I was hoping to to it without keystrokes as keystrokes are not reliable.
Basically what I need is the correct syntax of getting a handle to an element in the iframe without actually navigating into the Iframe
Something along the lines of this code.....

GoSub GetMSIE
Login = "dodo@gmail.com"
password = "dodo"
Gosub Enter_FrameElement
Exit

:Enter_FrameElement
WinIE_Name = msie.Document.title
iFrameCollection = msie.document.GetElementsByTagName("Iframe")
iFrameCount = iFrameCollection.length

For x = 0 to iFrameCount-1
   FrameObj = iFrameCollection.item(x)
   FrameName = FrameObj.name
   FrameId = FrameObj.id
   FrameUrl = FrameObj.Src
   Exist_FrameUrl = StrIndexNc (FrameUrl, "/secure/login", 1, @FWDSCAN)
   if Exist_FrameUrl == 0 then Next
   FrameObj.style.border = ".25mm solid red"

   ErrorMode(@OFF)
   FrameObj.getElementById("username") = "login"
   ;or
   FrameName.getElementById("username") = "login"
   ;or
   FrameId.getElementById("username") = "login"
   ;or
   FrameUrl.getElementById("username") = "login"

   FrameObj.getAttribute("username") = "login"
   ;or
   FrameName.getAttribute("username") = "login"
   ;or
   FrameId.getAttribute("username") = "login"
   ;or
   FrameUrl.getAttribute("username") = "login"
   ErrorMode(@Cancel)
   FrameObj.style.border = ".25mm solid black"
   break
Next

msie.document.FrameObj.GetElementByid("UserName").value = Login
   ;or
msie.document.FrameName.GetElementByid("UserName").value = Login
   ;or
msie.document.FrameId.GetElementByid("UserName").value = Login
   ;or
msie.document.FrameUrl.GetElementByid("UserName").value = Login
Return

:GetMSIE
   Shell = ObjectOpen("Shell.Application")
   For x = 0 To Shell.Windows.count-1
      swc = Shell.Windows.count-1
      ErrorMode(@OFF)
      swi = Shell.Windows.item(x)
      If !swi
         ErrorMode(@CANCEL)
         Continue
      EndIf
      swif =  Shell.Windows.item(x).fullname
      If !StrIndexNC(swif, "iexplore.exe", 1, @FWDSCAN)
         ErrorMode(@CANCEL)
         Continue
      EndIf

      msie=Shell.Windows.item(x)
      URL = msie.LocationURL
      URL_Valid = StrIndexNC(URL, "invest", 1, @FWDSCAN)
      If !URL_Valid
         ErrorMode(@CANCEL)
         Continue
      Else
         Break
      EndIf
      ErrorMode(@CANCEL)
   Next
Return

Ironically one of the iFrame examples in the Tech Database  was written by me for yahoo ages ago :)

stanl

Quote from: hdsouza on March 14, 2014, 01:30:42 PM
Guys, I think we going off topic here.

Not so fast. I don't believe either George or myself were off-topic. Attached I ran my ie_analysis script and the signonoff block does appear as a div (Item 188). That I believe has a click event which runs jscript.  This appears to make it difficult to detect the login as an iframe element, and that I why I mentioned jquery.

RAK

I have had this issue a few times - I use a simple solution that will allow com to see contents of iframes.  Obtain the url for the iframe and navigate to it. Then COM can see elements normally.

George Vagenas

So I entered a stock search at Investors and got this page as a result.
"http://research.investors.com/quotes/nasdaq-tower-semiconductor-ltd-tsem.htm?fromsearch=1"
If all you want to do is submit stock queries and scrape the returned pages for information the WinInet extender can probably do what you want. If the site has an option to remember your logon visiting it with Internet Explorer and using iCookieGet will take care of the logon.
Code (winbatch) Select
   AddExtender("wwint34i.dll")
   
   ; Define some stock strings.
   Stocks = 'nasdaq-tower-semiconductor-ltd-tsem'
   Stocks = Stocks:@tab:'nyse-first-acceptance-corp-fac'
   Stocks = Stocks:@tab:'nyse-mastercard-inc-cl-a-ma'
   
   Srvr = 'http://research.investors.com'
   ; Test the connection.
   Srvr = 'http://www.nzbplanet.net'
   Ok = iCookieGet(Srvr)
   If Ok==''
      Message('Investors.com logon Error!', iGetLastError())
      Exit
   EndIf
   
   ; Now loop thru a series of queries.
   Cnts = itemcount(Stocks, @tab)
   for Cnt = 1 to Cnts
      Stock = itemextract(Cnt, Stocks, @tab)
      Url = Srvr:'/quotes/':Stock:'.htm?fromsearch=1'
      icookieget(Srvr)
      hTop  = ibegin(0,"","")
      hData = iurlopen(hTop, Url)
      ; Test and process data.
      .
      .
      .
   next ;Cnt
Thanks

George

hdsouza

George, I appericiate the help although I do not need to search the site but to login to the site. That is the primary question and the only question on this post.
Also I cannot use the iframe url and navigate to the iframe as it does not have a login or continue button to proceed. In such cases one needs to navigate into the Iframe from the main page page itself
As I mentioned  in the past was i need is the correct syntax of getting a handle to an element in the iframe without actually navigating into the Iframe

George Vagenas

My apologies, I assumed there was something you wished to do once you were logged on.
Thanks

George