473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Frames in MSHTML

Hello all,

I am using the WebBrowser control to browse a webpage containing frames and am having difficulties accessing the 'frames' property of a document object. Bellow is my code and the error recieved:
webAccess.Navigate(URL);

// Wait until document is loaded. This part DOES work

IHTMLDocument2 mDoc = (IHTMLDocument2)(webAccess.Document);

IHTMLFramesCollection2 mFrames = (IHTMLFramesCollection2)(mDoc.frames);

The final line of code returns the error of:

An unhandled exception of type 'System.InvalidCastException' occurred in xxxx.exe

Additional information: No such interface supported

Does anyone out there know of a way to fix this? It would be greatly apreciated.

Nov 17 '05 #1
4 17607
Hi,

David Pendrey wrote:
I am using the WebBrowser control to browse a webpage containing
frames and am having difficulties accessing the 'frames' property of
a document object. An unhandled exception of type 'System.InvalidCastException'
occurred in xxxx.exe Does anyone out there know of a way to fix this? It would be greatly
apreciated.


Here's an excerpt of actual working code I wrote a while ago, which drills
down to the document contained in a frame named "main", and does things with
its contents. Hopefully that will help you:

mshtml.HTMLDocument doc = (mshtml.HTMLDocument)browser.Document;
mshtml.FramesCollection frames = (mshtml.FramesCollection)doc.frames;
mshtml.IHTMLWindow2 mainFrame = null;
for (int i = 0; i < frames.length; i++)
{
object refIndex = i;
mshtml.IHTMLWindow2 frame = (mshtml.IHTMLWindow2)frames.item(ref
refIndex);
if (frame.name == "main")
mainFrame = frame;
}
if (mainFrame != null)
{
mshtml.IHTMLDocument2 mainFrameDoc = mainFrame.document;
[...]
}

As I recall, I too encountered numerous invalid cast errors while trying to
interpret and folow the sparse documentation on this topic. I ended up
writing code to dump the actual type of all objects in the tree and referred
to that.
--
Chris Priede
Nov 17 '05 #2
Hi,

Thanks, that code is working better but still not well enough unfortunatly. I've fiddled around a bit and your code works fine when it's in the code being pressed by a button after you press a button to load the page. However if you have code to go to a page, then sleep until ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE and then use your code it doesn't work. I tried to wait a while (up to 5 seconds) and running your code in a seperate thread with no luck. Any ideas on this?

David Pendrey

"Chris Priede" <pr****@panix.com> wrote in message news:en**************@TK2MSFTNGP12.phx.gbl...
Hi,

David Pendrey wrote:
I am using the WebBrowser control to browse a webpage containing
frames and am having difficulties accessing the 'frames' property of
a document object.

An unhandled exception of type 'System.InvalidCastException'
occurred in xxxx.exe

Does anyone out there know of a way to fix this? It would be greatly
apreciated.


Here's an excerpt of actual working code I wrote a while ago, which drills
down to the document contained in a frame named "main", and does things with
its contents. Hopefully that will help you:

mshtml.HTMLDocument doc = (mshtml.HTMLDocument)browser.Document;
mshtml.FramesCollection frames = (mshtml.FramesCollection)doc.frames;
mshtml.IHTMLWindow2 mainFrame = null;
for (int i = 0; i < frames.length; i++)
{
object refIndex = i;
mshtml.IHTMLWindow2 frame = (mshtml.IHTMLWindow2)frames.item(ref
refIndex);
if (frame.name == "main")
mainFrame = frame;
}
if (mainFrame != null)
{
mshtml.IHTMLDocument2 mainFrameDoc = mainFrame.document;
[...]
}

As I recall, I too encountered numerous invalid cast errors while trying to
interpret and folow the sparse documentation on this topic. I ended up
writing code to dump the actual type of all objects in the tree and referred
to that.


--
Chris Priede

Nov 17 '05 #3
David Pendrey wrote:
Thanks, that code is working better but still not well enough
unfortunatly. I've fiddled around a bit and your code works fine when
it's in the code being pressed by a button after you press a button
to load the page. However if you have code to go to a page, then
sleep until ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
and then use your code it doesn't work. I tried to wait a while (up
to 5 seconds) and running your code in a seperate thread with no
luck. Any ideas on this?


My project was an automated sequence of about half a dozen steps, which logs
in to a site with a username/password, navigates to a specific page, submits
a search form on that page, and scrubs data from the results. The sequence
is driven by a timer and a state machine. Completion, timeout and errors
are detected through DocumentComplete and NavigateError events. This might
not be the greatest design, but it seems to work well enough under both
normal and error circumstances.

I never attempted to use ReadyState to detect completion. This is not to
say it wouldn't work, though.

If you use a separate thread, make sure you are using Invoke/BeginInvoke for
anything having to do with the browser control. It also appears necessary
to do so within any handlers for the browser control's events.
--
Chris Priede
Nov 17 '05 #4
Thank you for the assistance. I was running my code from invisde a seperate
thread from the main application so that the window would be automatically
redrawn and this appears to have been causing the problems. Now I run it all
in the same thread and simply use the following function to load a page and
wait until it is fully loaded:

protected HTMLDocument GotoPage(string URL)

{

while (webAccess.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)

{

System.Windows.Forms.Application.DoEvents();

System.Threading.Thread.Sleep(250);

}

webAccess.Navigate(URL);

while (webAccess.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)

{

System.Windows.Forms.Application.DoEvents();

System.Threading.Thread.Sleep(250);

}

return (HTMLDocument)(webAccess.Document);

}
Thank you again for all of your help :)
"Chris Priede" <pr****@panix.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
David Pendrey wrote:
Thanks, that code is working better but still not well enough
unfortunatly. I've fiddled around a bit and your code works fine when
it's in the code being pressed by a button after you press a button
to load the page. However if you have code to go to a page, then
sleep until ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
and then use your code it doesn't work. I tried to wait a while (up
to 5 seconds) and running your code in a seperate thread with no
luck. Any ideas on this?


My project was an automated sequence of about half a dozen steps, which
logs in to a site with a username/password, navigates to a specific page,
submits a search form on that page, and scrubs data from the results. The
sequence is driven by a timer and a state machine. Completion, timeout
and errors are detected through DocumentComplete and NavigateError events.
This might not be the greatest design, but it seems to work well enough
under both normal and error circumstances.

I never attempted to use ReadyState to detect completion. This is not to
say it wouldn't work, though.

If you use a separate thread, make sure you are using Invoke/BeginInvoke
for anything having to do with the browser control. It also appears
necessary to do so within any handlers for the browser control's events.
--
Chris Priede

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dean Hallman | last post by:
I need to ensure client machine has Microsoft.mshtml installed in the GAC. And if not, deploy it. My app is a Browser Helper Object and depends on mshtml. Initially, I thought I could take care...
4
by: Lars-Erik Aabech | last post by:
Hi! I've been walking in extacy since reading the article about test automation with IE in the latest MSDN mag. (http://msdn.microsoft.com/msdnmag/issues/05/10/TestRun/default.aspx) After a...
0
by: geertm | last post by:
Hello, I have a problem accessing frames using the MSHTML object. I tried this code ----------------------------------- For intindex = 0 To objDoc.frames.count - 1 .... Next...
5
by: Atara | last post by:
I am trying to convert the following code to VB .Net, I still have some gaps (the lines that are marked with (*)) and also I need an ending condition for the while loop. any help would be...
1
by: DK - Minneapolis | last post by:
I am trying to use the Web Browser in a VB .Net windows application to host external web sites. I have a problem when I try and capture one of the document objects events. I used the KB 311284...
0
by: Atara | last post by:
Our application was build with VS 2003. I have tried to run it on a computer with .Net 2.0 (but without .Net 1.1 , as it should be used) and I got the following error - ...
2
by: holder | last post by:
Folks, I have a simple web page with frames. I am trying to automate internet explorer to display the page and allow access to its frames. Here is the sample code : using mshtml; static void...
5
by: Jason | last post by:
Hi, I'm developing an HTML Editor Control using VB.Net 2003 for an application that used to use the DHTML Editor Control that is no longer supported. Well, it's been fun but I've hit a wall with...
1
by: michelqa | last post by:
Hi, I'm doing a kind of control picker like the one in spy++ but for html document. When the control picker is over an IFRAME, the mshtml function ElementFromPoint return an IFrame element....
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.