Peter Groves
asked on
I need to access elements from an existing child window to extrat info!
I need to access child elements of an existing web page to extract data.
First is code snippet of how the child window is opened!
Code I`m trying out but have no idea how to go about it!
I`ve read that IFRAMES might be a problem but this is the only reference I found and doesn`t seem to be in the affected area
Pete
First is code snippet of how the child window is opened!
window[name] = window.open(url,name,'width='+wid+',height='+hgt+',left='+lt+',top='+tp+',resizable,scrollbars');
The code I`m trying to access info below the plus signs is what I want to extract! +++++
<tr onclick="submitInfo( 45815, 'test.project.noreseau');"><div name="45815"><td class="search" bgcolor="ffffff" style="cursor: pointer"><a name="45815"> address - 6801, route Transcan, 2e</a><br> Autres 0810 L.B.</td></div>
Code I`m trying out but have no idea how to go about it!
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set els = oBrowser.document.getElementsByTagName("*")
For Each el In els
Debug.Print el.ID, el.Value
Next el
The above Debug prints pulls out all the elements except those within the child window! I`ve read that IFRAMES might be a problem but this is the only reference I found and doesn`t seem to be in the affected area
<iframe id="idFrame" name="isearch" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="no" src="searchFO.php?premier=oui&site=telusfo" width="100%" height="400px" onfocus="scwHide();" ></iframe>
ThanksPete
ASKER
I don`t have control on the page that opens the window. I'm just trying to scan an existing web page with an embeded child window in it!
So I need a code that can find how to address the window so I can access the document elements.
search open Windows -------- scan for the right one ------ so that I get something like:
childwin = foundwindow.document.getel ementby??? ?
thanks
Pete
So I need a code that can find how to address the window so I can access the document elements.
search open Windows -------- scan for the right one ------ so that I get something like:
childwin = foundwindow.document.getel
thanks
Pete
You can grab the window by its title.
Here's one method:
Then use this:
Here's one method:
Function IEWindowFromTitle(sTitle As String) As SHDocVw.InternetExplorer
Dim objShellWindows As New SHDocVw.ShellWindows
Dim win As Object, rv As SHDocVw.InternetExplorer
For Each win In objShellWindows
If TypeName(win.Document) = "HTMLDocument" Then
If UCase(win.Document.Title) = UCase(sTitle) Then
Set rv = win
Exit For
End If
End If
Next
Set IEWindowFromTitle = rv
End Function
Then use this:
childwin = IEWindowFromTitle("title of child window")
ASKER
I tried the code but realized the window I want doesn't have a title! Is there some other tag I can search for?
The code works as it shows all the open pages!
Thanks
Pete
The code works as it shows all the open pages!
Thanks
Pete
ASKER
I've found a few other ways to check for open windows nad thy all give the same result, which is not showing my missing window!
Now I'm trying to figure out what else to look for. I'm sure I have 2 distinct entities on the page as I see 2 source codes depending on where I click on the page.
The top part of the page selects the search criteria after submitting that the results show up in the bottom part along with the scroll bars etc.
I can see the tags I need on the source code of the bottom part only!
It must be inside an Iframe! There is one on the main page at the bottom of a table and I'm starting to think they put the results there.
Pete
Now I'm trying to figure out what else to look for. I'm sure I have 2 distinct entities on the page as I see 2 source codes depending on where I click on the page.
The top part of the page selects the search criteria after submitting that the results show up in the bottom part along with the scroll bars etc.
I can see the tags I need on the source code of the bottom part only!
It must be inside an Iframe! There is one on the main page at the bottom of a table and I'm starting to think they put the results there.
Pete
Post a link to your website.
You most likely should be using the NewWindow event of a browser to know and get the window.
Secondly the URL should and can be checked in the above code.
You most likely should be using the NewWindow event of a browser to know and get the window.
Secondly the URL should and can be checked in the above code.
ASKER
Unfortunately it's an intranet site! I'll look into the NewWindow aspect of it!
Thanks
Pete
Thanks
Pete
If the content is not so secret open the IE developer window and copy one of the main elements at the top like the body.
ASKER
This is where the iFrame shows up and so we know what the name is "idFrame"
<code> </span>
</td>
<tr>
<td>
<table width=100% cellspacing=0 cellpadding=0 style="border-style: solid; border-width:0px;">
<tr>
<td width=100% height=100%>
<iframe id="idFrame" name="isearch" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="no" src="searchFO.php?premier= oui&site=t elusfo" width="100%" height="400px" onfocus="scwHide();" ></iframe>
</td>
</tr>
</table>
</td>
</tr>
</table>
</code>
========================== ========== ========== ========
This is the part I'm trying to access, specifically and one of which is the ID of the data record!
This is part of the first row of a table ( which is all clickable) there is more date to this first row but left it out for clarity!
SO when I select a record and submit it on the upper part , that populates the iFrame in the lower part with records in a table!
Even though it is possible to request a range to show up in the table, for the purpose of
extracting the info I need , then there will always be only 1 record!
<code> <tr onclick="submitInfo( 45815, 'boss.project.network');"> <div name="45815"><td class="search" bgcolor="ffffff" style="cursor: pointer"><a name="45815"> cust move - 6801, route Transroute, 2e</a><br> Autres&nbs p; &n bsp; &nbs p; &n bsp; 0810 &nbs p; &n bsp; &nbs p; L.B.</td></div>
<td class="search" style="vertical-align:bott om;" bgcolor="ffffff" style="text-align:center; cursor:pointer;"><table width=100% border="0" style="border-width: 0px;" cellpadding=0 cellspacing=0><tr><td class="search" style="border-width: 0px; vertical-align:top;" bgcolor="ffffff"><center>< /center></ td></tr><t r><td class="search" style="border-width: 0px; vertical-align:bottom;" bgcolor="ffffff"><center>N /A</center ></td></tr ></table>< /td> </code>
I`m guessing I`ll have to go the iframe route with something like!
Dim testiframe As HTMLIFrame or HTMLDocument
testiframe.Document.Window .Frames("i search").D ocument.Bo dy.OuterHt ml
or
oBrowser.Document.getEleme ntsbyTagNa me("isearc h")(0).con tentDocume nt.getElem entsbyTagN ame("body" )(0).inner text
I'm just getting back into programming!( Last Tuesday to be exact LOL) Haven't coded since 2004. So I have to get used to how the different variables are declared and how to access them.
If any one has a good site I can consult to get back up to speed , I'd appreciate it!
Thanks
Pete
<code> </span>
</td>
<tr>
<td>
<table width=100% cellspacing=0 cellpadding=0 style="border-style: solid; border-width:0px;">
<tr>
<td width=100% height=100%>
<iframe id="idFrame" name="isearch" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="no" src="searchFO.php?premier=
</td>
</tr>
</table>
</td>
</tr>
</table>
</code>
==========================
This is the part I'm trying to access, specifically and one of which is the ID of the data record!
This is part of the first row of a table ( which is all clickable) there is more date to this first row but left it out for clarity!
SO when I select a record and submit it on the upper part , that populates the iFrame in the lower part with records in a table!
Even though it is possible to request a range to show up in the table, for the purpose of
extracting the info I need , then there will always be only 1 record!
<code> <tr onclick="submitInfo( 45815, 'boss.project.network');">
<td class="search" style="vertical-align:bott
I`m guessing I`ll have to go the iframe route with something like!
Dim testiframe As HTMLIFrame or HTMLDocument
testiframe.Document.Window
or
oBrowser.Document.getEleme
I'm just getting back into programming!( Last Tuesday to be exact LOL) Haven't coded since 2004. So I have to get used to how the different variables are declared and how to access them.
If any one has a good site I can consult to get back up to speed , I'd appreciate it!
Thanks
Pete
If I understand you correctly the first step you have to do is get the right Internet Explorer window. One way which is already indicated above is to search for it from the open explorer windows. This is a copy of what is above (There is no other way to do this as far as I know) but now checks the URL instead. Check all or part of the URL to know you have the right IE. I check both the URL and title in one of my programs.
Another possibility is to use the New Window event You would need to have an instance of the currently running IE or all of them if they have tabs open that is going to open the new window. Then if this NewWindow event is fired YOU start a new IE instance yourself and you set this instance to ppDisp
Function IEWindowFromTitle(theURL As String) As SHDocVw.InternetExplorer
Dim objShellWindows As New SHDocVw.ShellWindows
Dim win As Object, rv As SHDocVw.InternetExplorer
For Each win In objShellWindows
If TypeName(win.Document) = "HTMLDocument" Then
If UCase(win.Document.URL) = UCase(theURL) Then
Set rv = win
Exit For
End If
End If
Next
Set IEWindowFromTitle = rv
End Function
Another possibility is to use the New Window event You would need to have an instance of the currently running IE or all of them if they have tabs open that is going to open the new window. Then if this NewWindow event is fired YOU start a new IE instance yourself and you set this instance to ppDisp
Set ppDisp = myNewIE
This may or may not work on an intranet site as I have seen issues where your IE security settings effect the IE instance once it works out that it is a safe intranet site.
Once you have the right IE then the fun starts as I am sure there are 1000 ways to deal with your code.
As you are dealing with frames you must understand that a frame is like an IE inside your IE. For example your "top" IE could be sitting there ready and doing nothing but a frame somewhere inside which is in fact a IE window will have a HTMLDocument that is currently navigating and going to a new page.
1. How many frames does the top IE and HTMLDocument have?
2. If it has more than 1 are you sure you are trying to get the right one?
The first thing is that as you are trying to get a new IE that is just opening this means that the frame might no even exist yet. Further using the HTML too soon can cause issues. Thus my preferred first step with frames is to check it is even there.
Once the above finds that in the main htmldocument that the frame exists then you can get it. There are various ways to do this.
If you know which frame you want and the order does not change then. This gets the first frame in your main HTMLDocument and then gets the document ready to use.
The alternative is to use the getElementById function
I then do not understand what you want. Is it the number 45815? or what do you want?
As you are dealing with frames you must understand that a frame is like an IE inside your IE. For example your "top" IE could be sitting there ready and doing nothing but a frame somewhere inside which is in fact a IE window will have a HTMLDocument that is currently navigating and going to a new page.
1. How many frames does the top IE and HTMLDocument have?
2. If it has more than 1 are you sure you are trying to get the right one?
The first thing is that as you are trying to get a new IE that is just opening this means that the frame might no even exist yet. Further using the HTML too soon can cause issues. Thus my preferred first step with frames is to check it is even there.
Dim myHTMLDoc As HTMLDocument
'get the main HTML Document from the IE you have set elswhere
Set myHTMLDoc = IE.Document
'add here some loops for the ready state of IE and of the HTMLDocument if you like.
'first check they are on a licence file
If InStr(myHTMLDoc.documentElement.outerHTML, "id=""idFrame""") Then
'we now have the frame in the main HTMLDocument
End If
Once the above finds that in the main htmldocument that the frame exists then you can get it. There are various ways to do this.
If you know which frame you want and the order does not change then. This gets the first frame in your main HTMLDocument and then gets the document ready to use.
Set myHTMLFrameDoc = myHTMLDoc.frames(0).Document
The alternative is to use the getElementById function
Set myHTMLFrameDoc = myHTMLDoc.getElementById("idFrame").Document
I then do not understand what you want. Is it the number 45815? or what do you want?
ASKER
Hi , I think your suggestions are bang on and I'll try them as soon as the parting is over, the throbbing in my head stops and my vision is no longer blurry!
The 45815 is the record ID I need to retrieve to navigate to the results page were I have control!
So I probably won't touch much before the27th.
Anyways thanks and have a great holiday!
Pete
The 45815 is the record ID I need to retrieve to navigate to the results page were I have control!
So I probably won't touch much before the27th.
Anyways thanks and have a great holiday!
Pete
ASKER
Hope everyone had a great holiday! back to work now!
I keep getting a 424 error Object required on the indicated line!
<code>
Sub Test_print2()
Dim myHTMLDoc, myHTMLFrameDoc As HTMLDocument
Dim time1, time2
Dim doc As HTMLDocument
Dim myHTMLDoc, myHTMLFrameDoc As HTMLDocument
Dim workFrame As HTMLIFrame
Dim iframe As HTMLIFrame, src As String
Dim innerdoc
On Error GoTo Err_Clear
sURL = "http://permis.myintranet.com/index.php"
Set oBrowser = GetObject("new:{D5E8041D-9 20F-45e9-B 8FB-B1DEB8 2C6E5E}")
oBrowser.Silent = True
'oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
' Wait till the Browser is loaded
Do
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLdoc = oBrowser.document
'Set doc = oBrowser.document
HTMLdoc.all.Login.Value = "x123456"
HTMLdoc.all.Pwd.Value = "123456"
oBrowser.document.all.Item ("Btn").Cl ick
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
oBrowser.navigate "http://permis.telusquebec.com/bire/main.php?site=telusfo"
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
oBrowser.document.Links(2) .Click
'oBrowser.navigate "http://permis.telusquebec.com/bire/projet.php"
time1 = Now
time2 = Now + TimeValue("0:00:01")
Do Until time1 >= time2
DoEvents
time1 = Now()
Loop
' oBrowser.Refresh ' Refresh If Needed
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
time1 = Now
time2 = Now + TimeValue("0:00:01")
Do Until time1 >= time2
DoEvents
time1 = Now()
Loop
oBrowser.document.all.Item ("recherch e").Value = "2620157"
oBrowser.document.all.Item ("Btn").Cl ick
time1 = Now
time2 = Now + TimeValue("0:00:01")
Do Until time1 >= time2
DoEvents
time1 = Now()
Loop
Set myHTMLFrameDoc = myHTMLDoc.getElementById(" idFrame"). document ' <<<<<<< 424 error is here
time1 = Now
time2 = Now + TimeValue("0:00:01")
Do Until time1 >= time2
DoEvents
time1 = Now()
Loop
If Is Nothing Then
MsgBox "Form not found"
myHTMLFrameDoc.Quit
Else
MsgBox ("got here ID")
'we now have the frame in the main HTMLDocument
End If
Err_Clear:
If Err <> 0 Then
MsgBox ("Error=") & Err
Err.Clear
Resume Next
End If
'MsgBox ("Zoomed past here! ")
oBrowser.Quit
End Sub </code>
Pete
I keep getting a 424 error Object required on the indicated line!
<code>
Sub Test_print2()
Dim myHTMLDoc, myHTMLFrameDoc As HTMLDocument
Dim time1, time2
Dim doc As HTMLDocument
Dim myHTMLDoc, myHTMLFrameDoc As HTMLDocument
Dim workFrame As HTMLIFrame
Dim iframe As HTMLIFrame, src As String
Dim innerdoc
On Error GoTo Err_Clear
sURL = "http://permis.myintranet.com/index.php"
Set oBrowser = GetObject("new:{D5E8041D-9
oBrowser.Silent = True
'oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
' Wait till the Browser is loaded
Do
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLdoc = oBrowser.document
'Set doc = oBrowser.document
HTMLdoc.all.Login.Value = "x123456"
HTMLdoc.all.Pwd.Value = "123456"
oBrowser.document.all.Item
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
oBrowser.navigate "http://permis.telusquebec.com/bire/main.php?site=telusfo"
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
oBrowser.document.Links(2)
'oBrowser.navigate "http://permis.telusquebec.com/bire/projet.php"
time1 = Now
time2 = Now + TimeValue("0:00:01")
Do Until time1 >= time2
DoEvents
time1 = Now()
Loop
' oBrowser.Refresh ' Refresh If Needed
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
time1 = Now
time2 = Now + TimeValue("0:00:01")
Do Until time1 >= time2
DoEvents
time1 = Now()
Loop
oBrowser.document.all.Item
oBrowser.document.all.Item
time1 = Now
time2 = Now + TimeValue("0:00:01")
Do Until time1 >= time2
DoEvents
time1 = Now()
Loop
Set myHTMLFrameDoc = myHTMLDoc.getElementById("
time1 = Now
time2 = Now + TimeValue("0:00:01")
Do Until time1 >= time2
DoEvents
time1 = Now()
Loop
If Is Nothing Then
MsgBox "Form not found"
myHTMLFrameDoc.Quit
Else
MsgBox ("got here ID")
'we now have the frame in the main HTMLDocument
End If
Err_Clear:
If Err <> 0 Then
MsgBox ("Error=") & Err
Err.Clear
Resume Next
End If
'MsgBox ("Zoomed past here! ")
oBrowser.Quit
End Sub </code>
Pete
You have not set myHTMLDoc. Above you set a document to HTMLDoc but I think the document t has changed since then.
ASKER
I`ve found a way to navigate to the html refernced via the iFrame directly, so I don`t have to fool around with the iframe code.
But all is not lost for I still need help extracting the record ID!
SO I still need to access the recordID which in this case is 45815. As seen in this code!
<code> <tr onclick="submitInfo( 45815, 'bire.projet.noreseau');"> <div name="45815"><td class="search" bgcolor="ffffff" style="cursor: pointer"><a name="45815"> Déplace ment - 6801, route TransCanadienne, 2e</a><br> Autres&nbs p; &n bsp; &nbs p; &n bsp; 0810 &nbs p; &n bsp; &nbs p; L.B.</td></div>
<td class="search" style="vertical-align:bott om;" bgcolor="ffffff" style="text-align:center; cursor:pointer;"><table width=100% border="0" style="border-width: 0px;" cellpadding=0 cellspacing=0><tr><td class="search" style="border-width: 0px; vertical-align:top;" bgcolor="ffffff"><center>< /center></ td></tr><t r><td class="search" style="border-width: 0px; vertical-align:bottom;" bgcolor="ffffff"><center>N /A</center ></td></tr ></table>< /td> </code>
And I`ve used this to see what is in the div of which the legnth is 14
<code> Set divs = myHTMLDoc.getElementsByTag Name("div" )
For Each div In divs
Debug.Print "************************* ********** **"
Debug.Print div.getElementsByTagName(" div").Leng th
Next div </code>
I`ve been trying on my own to search for a way to access the 45815 in one of the three places it shows up but can`t get the right command structure to do so!
Hopfully it`s not to complicated!
Thanks again
Pete
But all is not lost for I still need help extracting the record ID!
SO I still need to access the recordID which in this case is 45815. As seen in this code!
<code> <tr onclick="submitInfo( 45815, 'bire.projet.noreseau');">
<td class="search" style="vertical-align:bott
And I`ve used this to see what is in the div of which the legnth is 14
<code> Set divs = myHTMLDoc.getElementsByTag
For Each div In divs
Debug.Print "*************************
Debug.Print div.getElementsByTagName("
Next div </code>
I`ve been trying on my own to search for a way to access the 45815 in one of the three places it shows up but can`t get the right command structure to do so!
Hopfully it`s not to complicated!
Thanks again
Pete
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK , I found a round about way but your way is better and less open to error. Since I only have one instance of "name" its pretty stable.
Thanks
Pete
Thanks
Pete
ASKER
Very helpful thanks
If post your code I'll try to adapt it.