salinasj
asked on
*URGENT* How can I get Frame(1) data after Frame(0) link clicked?
**URGENT HELP REQUIRED**
How can I get a known element from a document in frame 1 after having clicked a known link in frame 0 using WebBrowser control?
I have this:
Sub GetData(DestURL As String)
Dim WebBrowser: Set WebBrowser = CreateObject("InternetExpl orer.Appli cation")
Dim wPage As HTMLDocument
Dim pRes As String
' Make browser visible for debugging
WebBrowser.Visible = True
' Navigate to page
WebBrowser.navigate("http://" & DestURL)
Do While WebBrowser.busy
DoEvents
Loop
Set wPage = WebBrowser.document
' Click first link in frame(0)
wPage.frames(0).document.l inks(0).Cl ick
'
' HOW do I grab the value of element "MYFIELD" that has
' just loaded in frame(1) after I clicked the link in frame(0) ??
'
MsgBox "Value: " & pRes
End Sub
In viewing the visible browser, I can see that the new page is indeed loading in frame 1
after the click event fires.
And I've tried many permutations of
pRes = wPage.frames(1).All("MYFIE LD").Item. Value
but just can't seem to get it here...
The error I am getting is "Object doesn't support this property or method"
Any help would be greatly appreciated!
How can I get a known element from a document in frame 1 after having clicked a known link in frame 0 using WebBrowser control?
I have this:
Sub GetData(DestURL As String)
Dim WebBrowser: Set WebBrowser = CreateObject("InternetExpl
Dim wPage As HTMLDocument
Dim pRes As String
' Make browser visible for debugging
WebBrowser.Visible = True
' Navigate to page
WebBrowser.navigate("http://" & DestURL)
Do While WebBrowser.busy
DoEvents
Loop
Set wPage = WebBrowser.document
' Click first link in frame(0)
wPage.frames(0).document.l
'
' HOW do I grab the value of element "MYFIELD" that has
' just loaded in frame(1) after I clicked the link in frame(0) ??
'
MsgBox "Value: " & pRes
End Sub
In viewing the visible browser, I can see that the new page is indeed loading in frame 1
after the click event fires.
And I've tried many permutations of
pRes = wPage.frames(1).All("MYFIE
but just can't seem to get it here...
The error I am getting is "Object doesn't support this property or method"
Any help would be greatly appreciated!
ASKER
Nope.
that didn't do it either...
just now tried :
wPage.frames(0).document.l inks(0).cl ick
Do While WebBrowser.busy
DoEvents
Loop
Sleep 1000 ' Just givin it another second
Set wPage = WebBrowser.document
Sleep 1000 ' Just givin it another second
pRes = wPage.frames(1).document.b ody.innerH TML
MsgBox "HTML: " & vbCrLf & pRes
This DOES return the innerHTML of frame(1)
but it still won't let me getelementsbyname("MYFIELD ").Item.Va lue
See anything I might be missing here?
that didn't do it either...
just now tried :
wPage.frames(0).document.l
Do While WebBrowser.busy
DoEvents
Loop
Sleep 1000 ' Just givin it another second
Set wPage = WebBrowser.document
Sleep 1000 ' Just givin it another second
pRes = wPage.frames(1).document.b
MsgBox "HTML: " & vbCrLf & pRes
This DOES return the innerHTML of frame(1)
but it still won't let me getelementsbyname("MYFIELD
See anything I might be missing here?
okay...so "MsgBox "HTML: " & vbCrLf & pRes" is showing that you have the right html page, correct?
If so then how bout:
Dim oElement as Object
Set oElement = wPage.getElementsByName("M YFIELD")
then see what
msgbox oElement(0).Value
shows
Still not good. Then (sorry) are you sure about the name of the html element. You have checked the source code for spelling etc.?
What type of element is "MYFIELD" ?
Is it embedded in a form?
Dim oForm As Object
Set oForm = oBrowser.document.Forms(Yo urIndex)
then does msgbox oForm.MYFIELD do anything?
Is there any chance that frame1 has another frame or i-frame in it?
If so then how bout:
Dim oElement as Object
Set oElement = wPage.getElementsByName("M
then see what
msgbox oElement(0).Value
shows
Still not good. Then (sorry) are you sure about the name of the html element. You have checked the source code for spelling etc.?
What type of element is "MYFIELD" ?
Is it embedded in a form?
Dim oForm As Object
Set oForm = oBrowser.document.Forms(Yo
then does msgbox oForm.MYFIELD do anything?
Is there any chance that frame1 has another frame or i-frame in it?
salinasj,
this will get you past your first problem. I'll try to get back to you on ho to get the known element
Scott
Dim WebBrowser: Set WebBrowser = CreateObject("InternetExpl orer.Appli cation")
Dim wPage As HTMLDocument
Dim hw2 As HTMLWindow2
Dim pRes As String
' Make browser visible for debugging
WebBrowser.Visible = True
' Navigate to page
WebBrowser.navigate ("http://" & url)
Do While WebBrowser.busy
DoEvents
Loop
Set wPage = WebBrowser.document
' Click first link in frame(0)
If wPage.frames.length = 0 Then wPage.links(, 0).Click
If wPage.frames.length > 0 Then
Set hw2 = wPage.frames.Item(0)
If hw2.document.links.length > 0 Then
hw2.document.links(, 0).Click
End If
End If
this will get you past your first problem. I'll try to get back to you on ho to get the known element
Scott
Dim WebBrowser: Set WebBrowser = CreateObject("InternetExpl
Dim wPage As HTMLDocument
Dim hw2 As HTMLWindow2
Dim pRes As String
' Make browser visible for debugging
WebBrowser.Visible = True
' Navigate to page
WebBrowser.navigate ("http://" & url)
Do While WebBrowser.busy
DoEvents
Loop
Set wPage = WebBrowser.document
' Click first link in frame(0)
If wPage.frames.length = 0 Then wPage.links(, 0).Click
If wPage.frames.length > 0 Then
Set hw2 = wPage.frames.Item(0)
If hw2.document.links.length > 0 Then
hw2.document.links(, 0).Click
End If
End If
ASKER
Now it says : Object variable or With Block variable not set
Here's the exact code I'm using:
I cut out all the floof & have this basic code
WebBrowser.document.frames (0).docume nt.links(0 ).Click
Do While WebBrowser.busy
DoEvents
Loop
Sleep 1000
Dim oElement As Object
Set oElement = WebBrowser.document.frames (1).docume nt.getElem entsByName ("SYSNAME" )
MsgBox oElement(0).Value
Now, in watching the open (visible) browser during execution, I can see it load the initial page, then i see it load the new page into frame(1) after the click.
Here's the exact code I'm using:
I cut out all the floof & have this basic code
WebBrowser.document.frames
Do While WebBrowser.busy
DoEvents
Loop
Sleep 1000
Dim oElement As Object
Set oElement = WebBrowser.document.frames
MsgBox oElement(0).Value
Now, in watching the open (visible) browser during execution, I can see it load the initial page, then i see it load the new page into frame(1) after the click.
ASKER
Just for grins, I changed it to this to see if it is seeing the right page, and it is.
MsgBox "About to click"
WebBrowser.document.frames (0).docume nt.links(0 ).Click
Do While WebBrowser.busy
DoEvents
Loop
Sleep 1000
MsgBox "After click and after sleep"
MsgBox WebBrowser.document.frames (1).docume nt.body.in nerHTML
Dim oElement As Object
Set oElement = WebBrowser.document.frames (1).docume nt.getElem entsByName ("SYSNAME" )
MsgBox oElement(0).Value
the element "MYFIELD" is a SELECT tag within a form.
If I access the webpage directly (instead of through the frames like above) I can use getElementsByName("MYFIELD ").Item.Va lue
to get it.
but I can't do it like that because when I do, the page has javascript code in it that references the parent page and other frames. and this causes javascript errors that screw with the app. :(
MsgBox "About to click"
WebBrowser.document.frames
Do While WebBrowser.busy
DoEvents
Loop
Sleep 1000
MsgBox "After click and after sleep"
MsgBox WebBrowser.document.frames
Dim oElement As Object
Set oElement = WebBrowser.document.frames
MsgBox oElement(0).Value
the element "MYFIELD" is a SELECT tag within a form.
If I access the webpage directly (instead of through the frames like above) I can use getElementsByName("MYFIELD
to get it.
but I can't do it like that because when I do, the page has javascript code in it that references the parent page and other frames. and this causes javascript errors that screw with the app. :(
ASKER
k. thanks Scott.
I've gotta go home now, so will check after about an hour.
I really appreciate the help! ;)
-Jim
I've gotta go home now, so will check after about an hour.
I really appreciate the help! ;)
-Jim
ASKER
Oops!
I didn't see there were two people helping me...
Thanks to both of you.
Marshawk, in answer to your last question:
yes. it does display the innerHTML of frame(1) properly
I tried doing the oElement as Object, wPage.getElementsbyName("M YFIELD") but it gave me this error: Object variable or With Block variable not set
whenever i try to access oElement(0).Value
The name spelling of the html element is correct.
the "MYFIELD" element is a form SELECT field.
I also tried your example for a form object, but that yielded the same results.
There are no other frames within frame1.
There are no i-frames within frame1
There ARE 2 forms within frame1, but this element is in the first form
DiveBlue,
Thanks for the alternate way to traverse the frames.
It is more efficient than the way I was planning to do it.
And am anxiously awaiting your returned help with getting the known element from the newly loaded page in frame(1) after the click event.
I didn't see there were two people helping me...
Thanks to both of you.
Marshawk, in answer to your last question:
yes. it does display the innerHTML of frame(1) properly
I tried doing the oElement as Object, wPage.getElementsbyName("M
whenever i try to access oElement(0).Value
The name spelling of the html element is correct.
the "MYFIELD" element is a form SELECT field.
I also tried your example for a form object, but that yielded the same results.
There are no other frames within frame1.
There are no i-frames within frame1
There ARE 2 forms within frame1, but this element is in the first form
DiveBlue,
Thanks for the alternate way to traverse the frames.
It is more efficient than the way I was planning to do it.
And am anxiously awaiting your returned help with getting the known element from the newly loaded page in frame(1) after the click event.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SWEET!
You just made my weekend!
You get the 500pts and an A for awesome support!
Although DiveBlue did also enlighten me with a much better way to traverse the frames within the set...
I think he deserves credit for that.
I'll post in CS requesting an adjustment be made towards his efforts as well.
Again,
Thank You for your assistance!
-Jim
You just made my weekend!
You get the 500pts and an A for awesome support!
Although DiveBlue did also enlighten me with a much better way to traverse the frames within the set...
I think he deserves credit for that.
I'll post in CS requesting an adjustment be made towards his efforts as well.
Again,
Thank You for your assistance!
-Jim
DiveBlue,
salinasj has made a question for you to collect some points for you assistance on this question. It is at:
https://www.experts-exchange.com/questions/20543558/Points-for-DiveBlue-re-20542984.html
SpideyMod
Community Support Moderator @Experts Exchange
salinasj has made a question for you to collect some points for you assistance on this question. It is at:
https://www.experts-exchange.com/questions/20543558/Points-for-DiveBlue-re-20542984.html
SpideyMod
Community Support Moderator @Experts Exchange
Do While WebBrowser.busy
DoEvents
Loop
after your wPage.frames(0).document.l
pRes = wPage.frames(1).All("MYFIE
Probably you are trying to access frame1 before it has loaded and before its MSHTML HTMLDocument property is useable.
Use the url property in your documentcomplete event to see what is coming thru and when.
Plus if its not that try this syntax:
oBrowser.document.All.Item