Trying to click Javascript menu tree in IE (1 Viewer)

gypsyjoe11

Registered User.
Local time
Today, 14:37
Joined
Feb 19, 2010
Messages
46
Hi Everyone,

I'm trying to automate getting information from inside of IE. I'm making an IE object from an already open browser window. All of the pages on this site are setup with 2 frames on each. The first frame(0) has top navigation links that don't change. The second frame(1) is what changes.

Next I use the second frame to navigate to the appropriate page using:

Code:
Do: Loop Until Not IEwindow.Busy    'wait until IE is finished loading
SubFrame1.URL = "[URL]https://hr.xxx.us/servlets/iclientservlet/xxxx/?ICType=Nav[/URL]"

Next I need to expand the Javascript tree on the left and go to the right page. After expanding the tree and hovering over the correct text it says,

Code:
javascript:parent.treeControl.SelectNode("View Course Profile",15)

in the hover text.

The results from

Code:
Debug.Print IEwindow.document.frames(1).document.all.item(0).innerHTML

Are:

Code:
<HEAD>
<SCRIPT language=JavaScript src="/xxxx/xx/xxx/xx/PT_NAVMAIN_SCRIPT_ENG_ICNav_1.js"></SCRIPT>
<SCRIPT language=JavaScript src="/xxxx/xx/xxx/xx/PT_NAVTREE_ENG_ICNav_1.js"></SCRIPT>
<SCRIPT language=javascript src="/xxxx/xx/xxx/xx/PT_SAVEWARNINGSCRIPT_ENG_ICNav_1.js">
</SCRIPT>
<SCRIPT language=javascript src="/xxxx/xx/xxx/xx/PT_ISCROSSDOMAIN_ENG_ICNav_1.js">
</SCRIPT>
<SCRIPT language=JavaScript>
var targetURL='/xx/xxxxx/xx/';
var imageURL='';
var P=window;
var styleSheetURL='/xxxx/xx/xxx/xx/PSSTYLEDEF_ENG_1.css';
var iconBP = '/xxxx/xx/xxx/xx/PT_WF_BUSPROC_ENG_1.gif';
var iconAC = '/xxxx/xx/xxx/xx/PT_WF_ACTIVITY_ENG_1.gif';
var iconST = '/xxxx/xx/xxx/xx/PT_WF_STEP_ENG_1.gif';
var iconTNMN = '/xxxx/xx/xxx/xx/PT_TREENODE_MINUS_ENG_1.gif';
var iconTNPL = '/xxxx/xx/xxx/xx/PT_TREENODE_PLUS_ENG_1.gif';
var elmNum='0';
var selectedNodeType='B';
var selectedNodeName="xx_xxx_xxx_xxx";
P.Position("B","xx_xxx_xxx_xxx","/xx/xx/xxx/xxx/xxxx==_207.JPG","xxx Admin System - xxx Process Map");
P.Child("B","xxxx","xxx",127,267,157,297);
</SCRIPT>
<SCRIPT language=JavaScript>
LoadMain();
</SCRIPT>
</HEAD><FRAMESET rows=20,*><FRAME title="Menu Navigation" border=0 name=bread marginWidth=0 marginHeight=0 src="JavaScript:void(parent.LoadBread(parent.treeControl.GetRootNode()))" frameBorder=no scrolling=no><FRAMESET cols=210,*><FRAME title="Tree Navigation" border=0 name=leftF marginWidth=0 marginHeight=0 src="JavaScript:void(parent.LoadLeft(true))" frameBorder=no><FRAME title="Main Content" border=0 name=rightF marginWidth=0 marginHeight=0 src="JavaScript:void(parent.LoadImage())" frameBorder=no></FRAMESET></FRAMESET>
<BODY></BODY>

I can't figure out how to activate it though. I've tried all kinds of variations of

Code:
Call SubFrame1.parentWindow.execScript("parent.treeControl.SelectNode('View Course Profile',15)", "JavaScript")

and

Code:
Call SubFrame1.parentWindow.execScript("void(parent.LoadBread(parent.treeControl.GetRootNode()))", "JavaScript")

If anyone can help I'd greatly appreciate it. I'm stuck.

Joe
 

ajetrumpet

Banned
Local time
Today, 13:37
Joined
Jun 22, 2007
Messages
5,638
activate WHAT exactly? what are you trying to activate? what is the page? OR is that confidential? have you seen my faq on this sort of stuff? js code for navigation inside of frames is not in the faq but there might be another alternative. I didn't even know you could reference an IE frame with vba code....so you're on to something that I don't have experience with. I like this kind of stuff, so I could try out a few things if your school (I assume it's a school) is not required to keep their address confidential

but it looks like you're doing this stuff after you've logged into a site of somekind, so obviously I couldn't help you in that case.
 

ajetrumpet

Banned
Local time
Today, 13:37
Joined
Jun 22, 2007
Messages
5,638
I forgot to tell you...you might want to check out the SWDOCVW library if you don't have it. i don't know the method that you are using, but if you don't have that lib in your refs it's sometimes helpful. It gives you the HTML subcat's too that you can look at and explore. something may be there that you can use:

 

gypsyjoe11

Registered User.
Local time
Today, 14:37
Joined
Feb 19, 2010
Messages
46
Thanks ajetrumpet,

I am using SHDocVw. It's a human resources website at work. I didn't want to automate people's login user/password for security reasons and I don't want to write anything in case the program messes up (It's a live site). I would like to automate the getting of information for my department.

It's a html javascript menu tree that sits on the left side of the window. Of course sinse it's using frames the page's view html source isn't any help (it always lists the same code). I've viewed all the innerHTML and innerText for all the objects in both frames and I can't find the text shown that I want to click on.

This is my code so far:

Code:
Public Sub Get_DA()
    On Error GoTo Error_Get_DA
    Dim DisplayBox As VbMsgBoxResult
  'find the right internet explorer webpage
    Dim allExplorerWindows As New SHDocVw.ShellWindows
    Set allExplorerWindows = New SHDocVw.ShellWindows
 
    Dim IEwindow As SHDocVw.InternetExplorer
    Dim foundFlag As Boolean
    foundFlag = False
 
    For Each IEwindow In allExplorerWindows
        If InStr(IEwindow.LocationURL, ".xxxxxx.us") <> 0 Then
            foundFlag = True
            Exit For    'found the right IE window URL
        End If
    Next
 
    If Not foundFlag Then
        DisplayBox = MsgBox("Could not find an open instance of xxxxxx running." _
            & vbNewLine & vbNewLine & " " & _
            "You can contact the program author if assistance is needed." & _
            vbNewLine & "xxxxx" & _
            vbNewLine & "email at xxxxxx", _
            vbOKOnly + vbMsgBoxSetForeground, "Please try again.")
        GoTo Exit_Get_DA
    End If
    IEwindow.Visible = True      'set IE window to active
  'end find
    'set myHTMLDoc to the main pages IE document
    Dim myHTMLDoc As HTMLDocument
    Set myHTMLDoc = IEwindow.document
 
    'get sub frame0 from myHTMLDoc
    Dim SubFrame0 As HTMLDocument
    Set SubFrame0 = myHTMLDoc.frames(0).document
 
    'get sub frame1 from myHTMLDoc
    Dim SubFrame1 As HTMLDocument
    Set SubFrame1 = myHTMLDoc.frames(1).document
 
    'Navigate frame1 to the proper location
    Do: Loop Until Not IEwindow.Busy    'wait until IE is finished loading
    SubFrame1.URL = "[URL]https://hr.xxx.us/xxx/xxx/xxx/?ICType=Nav[/URL]"
 
    'print out all the objects in subframe1
    Dim objectElement As Object
 
    For Each objectElement In SubFrame1.all
        Debug.Print objectElement.tagName
        Debug.Print objectElement.innerText
        Debug.Print objectElement.innerHTML
    Next
    'print out all the scripts in subframe1
    Dim allScripts As Object
    Set allScripts = SubFrame1.Scripts
    Dim scriptElement As HTMLScriptElement
 
    For Each scriptElement In allScripts
        Debug.Print scriptElement.tagName
        Debug.Print scriptElement.innerText
        Debug.Print scriptElement.innerHTML
    Next  
 
    'print out the header
    Debug.Print IEwindow.document.frames(1).document.all.item(0).innerHTML
 
Exit_Get_DA:
    Exit Sub
Error_Get_DA:
    DisplayBox = MsgBox("Error Number is " & Err.Number & vbNewLine & _
        "Error Description is " & Err.Description _
        & vbNewLine & vbNewLine & " " & _
        "You can contact the program author if assistance is needed." & _
        vbNewLine & "xxxxxx" & _
        vbNewLine & "email at xxxxx", _
        vbOKOnly + vbMsgBoxSetForeground, "Error.")
    Resume Exit_Get_DA
End Sub

This is the results from the printing out of the scripts:

Code:
SCRIPT
 
SCRIPT
 
SCRIPT
 
SCRIPT
 
SCRIPT
 
var targetURL='/servlets/iclientservlet/xxx/';
var imageURL='';
var P=window;
var styleSheetURL='/servlets/cs/xxx/cache/PSSTYLEDEF_ENG_1.css';
var iconBP = '/servlets/cs/xxx/cache/PT_WF_BUSPROC_ENG_1.gif';
var iconAC = '/servlets/cs/xxx/cache/PT_WF_ACTIVITY_ENG_1.gif';
var iconST = '/servlets/cs/xxx/cache/PT_WF_STEP_ENG_1.gif';
var iconTNMN = '/servlets/cs/xxx/cache/PT_TREENODE_MINUS_ENG_1.gif';
var iconTNPL = '/servlets/cs/xxx/cache/PT_TREENODE_PLUS_ENG_1.gif';
var elmNum='0';
var selectedNodeType='B';
var selectedNodeName="CG_TRNG_SYS_BPM";
P.Position("B","xx_xx_xx_xx","/xxxxx/cs/xxxx/cache/xxxxxxxxxx==_207.JPG","Training Admin System - Business Process Map");
P.Child("B","CG_TRNG_SYS_BP","TAS",127,267,157,297);
SCRIPT
 
LoadMain();

I'm wondering if there is a way to fire an event in the header? Not sure how though?

I appreciate any help with this,

Joe
 

darbid

Registered User.
Local time
Today, 20:37
Joined
Jun 26, 2008
Messages
1,428
Hi I like this kind of stuff too.

In my opinion you should forget the JavaScript function. You should be trying to find the "Button/text/link" or what ever it is that people click on with their mouse and you should "click" on this with your code. The reason for this is the coder of the page might have other events that fire first or with the clicking of this button/text/link.

Once you are on the right place can you check how many FRAMES you have.

For example clicking on the root of the tree might load a a new frame for the choices? (I think this is old HTML coding but I have seen this for menus).

You might need to give us all the frames that are loaded into IE so that we can find what you are looking for.
 

ajetrumpet

Banned
Local time
Today, 13:37
Joined
Jun 22, 2007
Messages
5,638
darbid,

web pages are not completely compatible with vba. you have to put up with that, there's no way around it. frames are one of the tough obstacles, and possibly incompatible. if you have an answer for this thread though, by all means help him out! :)
 

gypsyjoe11

Registered User.
Local time
Today, 14:37
Joined
Feb 19, 2010
Messages
46
It's a menu tree that is displayed with Javascript so there is no button to click on.
 

ajetrumpet

Banned
Local time
Today, 13:37
Joined
Jun 22, 2007
Messages
5,638
It's a menu tree that is displayed with Javascript so there is no button to click on.

hey joe. do us a favor pls...log into your HR website and take a screenshot of this webpage with the js tree on it. expand a section of it with your mouse just for reference.

use the paint program or something to white out the sensitive stuff and post it up here (if your IT dep. hasn't shut the prntscr key that is!)
 

darbid

Registered User.
Local time
Today, 20:37
Joined
Jun 26, 2008
Messages
1,428
frames are one of the tough obstacles, and possibly incompatible.
In my experience HTML Frames are not hard to deal with ONCE they are loaded into the Browser. Each frame is like a HTML page.

if you have an answer for this thread though, by all means help him out! :)
I have no idea really if I have an answer. It is a pitty we cannot see the page.

It's a menu tree that is displayed with Javascript so there is no button to click on.
From my VERY limited experience of web pages and HTML there is always something in the HTML that calls the javascript function which might be on this page or in a .js.

Once we have proven me wrong and exhausted that possibility you might have to try to focus on two events which I think are also available to IE. I use the WebBrowser Control which has two events

BeforeNavigate2 and DocumentComplete.

See below as an example of the BeforeNavigate - the trick is to get the pDisp info out as you will see. I have not tested what is below but it should be close to error free. All references to "wb_ipas_Main_" you will have to change to your IE object.

This is going to maybe give you an idea of what things are being called upon execution of a choice in the tree.

Also the DocumentComplet "should" (i am not guaranteeing it) be fired for each frame or call for information after clicking on a choice.

Code:
Private Sub wb_ipas_Main_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
On Error GoTo Err_wb_ipas_Main_BeforeNavigate2

Dim TestString As String
Dim testa As Integer
    
    If Len(PostData) <> 0 Then
        Dim MyVar As Variant
    
        MyVar = PostData
        If VarType(MyVar) = (vbArray Or vbByte) Then
            Dim Bytes() As Byte
            Bytes = MyVar
            For testa = 1 To 500
              If Bytes(testa) = 0 Then Exit For
              TestString = TestString + Chr(Bytes(testa))
            Next testa
            
        Debug.Print "POST DATA - " & URL & " Post-" & TestString & " Flag-" & Flags & " Header-" & Headers & " Target-" & TargetFrameName
         
        End If
    End If


Exit_wb_ipas_Main_BeforeNavigate2:
    Exit Sub

Err_wb_ipas_Main_BeforeNavigate2:
    MsgBox Err.Description & " Error No." & Err.Number
    Resume Exit_wb_ipas_Main_BeforeNavigate2
End Sub
 

darbid

Registered User.
Local time
Today, 20:37
Joined
Jun 26, 2008
Messages
1,428
It's a menu tree that is displayed with Javascript so there is no button to click on.
Do you mean that it is a Java Applet? Then I would agree you cannot "click" on it with VBA.
 

gypsyjoe11

Registered User.
Local time
Today, 14:37
Joined
Feb 19, 2010
Messages
46
The first attached screenshot is after the user has logged in and my program has taken control and went to the TAS module of the system.

The second screenshot is taken after I have expanded the tree and clicked on a few levels.

I went to my IE history and looked at all the pages for this site that it recorded. Screenshot 3 was taken after setting the URL for the subframe to that URL.

Code:
SubFrame1.URL = "[URL]https://hr.xxx.us/xxx/xxx/xxxx/?ICType=Panel&Menu=ADMINISTER_TRAINING_(GBL)&Market=GBL&PanelGroupName=COURSE_TABLE2[/URL]"
 

Attachments

  • screenshot1.JPG
    screenshot1.JPG
    73.8 KB · Views: 328
  • screenshot2.jpg
    screenshot2.jpg
    98.2 KB · Views: 284
  • screenshot3.JPG
    screenshot3.JPG
    74.9 KB · Views: 296

ajetrumpet

Banned
Local time
Today, 13:37
Joined
Jun 22, 2007
Messages
5,638
so what i'm gathering here is that you want to automate the movement all the way through the point where people have to fill in the boxes in the 3rd ss? is that the point of this? i'm sure you can fill the boxes already, but the issue is expanding the tree levels, right?

i'm sorry joe but i've never dealt with a tree before. got a sample website with a js tree on it that I can use to test the code that I know how to use? if you got one, i'll make a few tests and see if i can give you any answers


btw, how much are you into the gypsie culture? are you really a gypsie? :D
 

gypsyjoe11

Registered User.
Local time
Today, 14:37
Joined
Feb 19, 2010
Messages
46
No the program is going to enter stuff in but I was going to wait to get stuck on that until after I figured out the tree navigation. I previously had meant to say that I just didn't want to automate the user login screen.
 

ajetrumpet

Banned
Local time
Today, 13:37
Joined
Jun 22, 2007
Messages
5,638
well like i said below, give me a website with a js tree on it and I'll see what i know how to do for you. you can learn how to fill the boxes in my FAQ page, if you haven't looked at it yet
 

darbid

Registered User.
Local time
Today, 20:37
Joined
Jun 26, 2008
Messages
1,428
My suggestion is have your page open like in screen shot 2.

Then click around the tree with the right mouse button and view source code. Doing this in FireFox is better but I assume your intranet site is fixed to IE.

Then do a text search of the source code for "View course profile".

This might not work which will mean you will then have to do print outs of the OuterHTML of every frame on this page. Note that debug.print is limited in the number of characters so a big HTML page will not fully show in the window.

IE is not magic, for it to display this tree it has to have it as HTML on the main page or in a frame, except if it is a Java Applet.

edit: Print out of each frame and sub frame as you have posted. You really need to check for all frames and subframes. That exist and are created through expanding this tree.
 
Last edited:

gypsyjoe11

Registered User.
Local time
Today, 14:37
Joined
Feb 19, 2010
Messages
46
It turns out that the subframe that I was working with is in turn made up of several subframes. I found the right one and navigated it to the page in my browser history. But the javatree on the left is not expanded. I suppose it doesn't really matter, but I would like to know how to control the bloomen thing..Tired of all the subframes within subframes #$#$#$?
 

Attachments

  • screenshot4.JPG
    screenshot4.JPG
    77.7 KB · Views: 183

darbid

Registered User.
Local time
Today, 20:37
Joined
Jun 26, 2008
Messages
1,428
Failing that I see you have a test system. If you can use this it might then not be confidential. You could then use IE to save the page fully with all needed files attached.

Go offline and then click on what you have saved to test it works. It might not look pretty and there might be a few error messages but it will pretty much show the structure of what you are dealing with.

You could then PM us/me that you have done this and I would give you my email to send it to me.
 

darbid

Registered User.
Local time
Today, 20:37
Joined
Jun 26, 2008
Messages
1,428
It turns out that the subframe that I was working with is in turn made up of several subframes. I found the right one and navigated it to the page in my browser history. But the javatree on the left is not expanded. I suppose it doesn't really matter, but I would like to know how to control the bloomen thing..Tired of all the subframes within subframes #$#$#$?

Once you find the right Frame/Subframe where "TAS" exists then it is most likly going to be a HTMLLinkElement. Once you get this HTMLLinkElement you can then click it which will expand the tree.
 

gypsyjoe11

Registered User.
Local time
Today, 14:37
Joined
Feb 19, 2010
Messages
46
I can't find any of the text I'm looking for. I think they must be burried within frames. Has anyone wrote a vba program to search for text and keep going down levels until it finds it. Then it reports the path back?

thanks for all the advice
 

darbid

Registered User.
Local time
Today, 20:37
Joined
Jun 26, 2008
Messages
1,428
I can't find any of the text I'm looking for. I think they must be burried within frames. Has anyone wrote a vba program to search for text and keep going down levels until it finds it. Then it reports the path back?

thanks for all the advice

Here is some air code I just put together. You need to add this to a routine that finds the IE object. It only goes to subframes you might have to extend it one more level.

I am pretty sure that the number of frames and subframes change after you click on the tree. So you might have to fun this a number of times with the tree closed and then open.


Code:
Dim myHTMLDoc As HTMLDocument
Dim myHTMLFrame As HTMLDocument
Dim myHTMLSubFrame As HTMLDocument

Dim DesktopPath As String
Dim i As Integer
Dim j As Integer

On Error Resume Next

i = 0
j = 0


DesktopPath = "Pathtodesktop" & "myhtml.txt"

Open DesktopPath For Append As #1

'get the main HTML Document
Set myHTMLDoc = IEwindow.Document

Print #1, "Main HTML DOC"
Print #1, myHTMLDoc.documentElement.outerHTML
Print #1, "************************"
Print #1, " "

For Each myHTMLFrame In myHTMLDoc

Print #1, "Frame - " & i
Print #1, myHTMLFrame.documentElement.outerHTML
Print #1, "************************"
Print #1, " "

    For Each myHTMLSubFrame In myHTMLFrame.Document
    
    Print #1, "Frame - " & i & " SubFram - " & j
    Print #1, myHTMLSubFrame.documentElement.outerHTML
    Print #1, "************************"
    Print #1, " "
    
    
    j = j + 1
    
    Next 


i = i + 1

Next

Close #1
 

Users who are viewing this thread

Top Bottom