473,748 Members | 10,048 Online
Bytes | Software Development & Data Engineering Community
+ 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.Navig ate(URL);

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

IHTMLDocument2 mDoc = (IHTMLDocument2 )(webAccess.Doc ument);

IHTMLFramesColl ection2 mFrames = (IHTMLFramesCol lection2)(mDoc. frames);

The final line of code returns the error of:

An unhandled exception of type 'System.Invalid CastException' 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 17645
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.Invalid CastException'
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.HTMLDocu ment doc = (mshtml.HTMLDoc ument)browser.D ocument;
mshtml.FramesCo llection frames = (mshtml.FramesC ollection)doc.f rames;
mshtml.IHTMLWin dow2 mainFrame = null;
for (int i = 0; i < frames.length; i++)
{
object refIndex = i;
mshtml.IHTMLWin dow2 frame = (mshtml.IHTMLWi ndow2)frames.it em(ref
refIndex);
if (frame.name == "main")
mainFrame = frame;
}
if (mainFrame != null)
{
mshtml.IHTMLDoc ument2 mainFrameDoc = mainFrame.docum ent;
[...]
}

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.tagREAD YSTATE.READYSTA TE_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.c om> wrote in message news:en******** ******@TK2MSFTN GP12.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.Invalid CastException'
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.HTMLDocu ment doc = (mshtml.HTMLDoc ument)browser.D ocument;
mshtml.FramesCo llection frames = (mshtml.FramesC ollection)doc.f rames;
mshtml.IHTMLWin dow2 mainFrame = null;
for (int i = 0; i < frames.length; i++)
{
object refIndex = i;
mshtml.IHTMLWin dow2 frame = (mshtml.IHTMLWi ndow2)frames.it em(ref
refIndex);
if (frame.name == "main")
mainFrame = frame;
}
if (mainFrame != null)
{
mshtml.IHTMLDoc ument2 mainFrameDoc = mainFrame.docum ent;
[...]
}

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.tagREAD YSTATE.READYSTA TE_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 DocumentComplet e 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.Read yState != SHDocVw.tagREAD YSTATE.READYSTA TE_COMPLETE)

{

System.Windows. Forms.Applicati on.DoEvents();

System.Threadin g.Thread.Sleep( 250);

}

webAccess.Navig ate(URL);

while (webAccess.Read yState != SHDocVw.tagREAD YSTATE.READYSTA TE_COMPLETE)

{

System.Windows. Forms.Applicati on.DoEvents();

System.Threadin g.Thread.Sleep( 250);

}

return (HTMLDocument)( webAccess.Docum ent);

}
Thank you again for all of your help :)
"Chris Priede" <pr****@panix.c om> wrote in message
news:%2******** *******@TK2MSFT NGP15.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.tagREAD YSTATE.READYSTA TE_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 DocumentComplet e 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
7766
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 of deploying mshtml within my install ..msi (VS.NET setup/deploy project). But if I simply add mshtml to the GAC from my install, the install fails near the end with the error:
4
3311
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 while, I had to find an issue I couldn't solve. (Of course) If an ASP.NET page uses the smartnav option, the document you get from IE only contains the viewstate input etc, the scripts and an IFrame.
0
1241
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
10920
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 appreciated. Thanks. Atara. ------------------------- Original code:
1
1538
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 "How to handle...VB .Net". coied all the code into my version of VS 2003. The code contains "AddHandler..." code, when active doesn't allow the textbox to recieve input, and the text links don't navigate to the next URL. When I comment out all...
0
2238
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 - System.InvalidCastException: Unable to cast COM object of type 'mshtml.HTMLBodyClass' to class type ''. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type....
2
4507
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 Main(string args) {
5
3884
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 an intermittent problem working with editing Hyperlinks. As you can see the following HTML code contains two links each in a paragraph tag. In the Editor, when I highlight the first link and execute code to select,
1
8720
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. How can I identify this particular frame/iframe in the frame collection??? I can only select frame in the framecollection by using
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9243
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
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 we have to send another system

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.