|
-
Jul 30th, 2011, 06:08 PM
#1
Thread Starter
PowerPoster
WebBrowser control and iframes
I'm trying to get hold of the iframe elements and its content.
Basically, there is a site which has a webpage and within it, it has alot of elements (divs etc...) and within it, an iframe. I can see all the content in the iframe via the developer toolbar and also the view source no problem.
The thing is I need to "interrogate" the iframe and its content but cannot seem to find out a way of doing this using the webbrowser control. it works fine for non iframe stuff I guess. The closest match ive been able to get is the iframe element.
The HTML tags/code in developer toolbar looks something like the following:
Code:
..
..
<body>
<div id="pagelet_presence">
<div id="blueBar" />
<div id="globalContainer">
<div class="sitecontent clearfix" id="content">
<div id="mainContainer">
<div id="contentCol">
<div id="contentArea">
<div id="pagelet_canvas_content">
<div id="pagelet_iframe_canvas_content">
<div>
<iframe name="iframe_canvas_https" height="600".................>
<!DOCTYPE html public..............>
<html>
<head>
<body>
<div id="demoWrapper">
..
..
..
</div>
</body>
</head>
</html>
</div>
</div>
..
..
so its a main page with loads of divs and within it it eventually gets down to the iframe which is serving up some site but cannot obtain the site its serving as there is no indication of it at all.
Anyway, does anyone have any ideas AT ALL on how I can get into the iframe content?
the code ive currently got is simple, and can get up to the "iframe_canvas_https" element and not anything below that which is where I need to go to get the "demoWrapper" div elements.
doing a simple "this.webBrowser.Document.GetElementById("demoWrapper")" does not bring back anything.
Code:
HtmlElement potentialIFrame = this.webBrowser.Document.GetElementById("iframe_canvas_https");
is the current code.
its getting frustrating. I just want to get elements within that iframe. And yes, the page has been loaded fully at this point.
-
Jul 31st, 2011, 06:42 AM
#2
Re: WebBrowser control and iframes
GetElementById only retrieves elements with the corresponding 'id' tag.
What you seem to be referring to is the 'name' tag.
I'm not big on the HTML DOM but I think you might get something with this:
Code:
window.frames["iframe_canvas_https"].document
Delete it. They just clutter threads anyway.
-
Jul 31st, 2011, 06:48 AM
#3
Thread Starter
PowerPoster
Re: WebBrowser control and iframes
well yes, thats fine. I can get that... and I know what GetElementById does.... but the problem is, I cannot seem to get past "iframe_canvas_https" at all.
-
Aug 1st, 2011, 09:48 AM
#4
Re: WebBrowser control and iframes
I'm no expert at this...
I don't think you can find the element with the demowrapper Id because you are looking at the wrong document.
As far as I know the webbrowser control does not have any support for the frames collection where one would normally find the other documents.
Does this output the elusive URL you are looking for?
Code:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Console.WriteLine("Document Complete: {0}", e.Url);
if (e.Url == webBrowser1.Url)
{
Console.WriteLine("finally!");
}
}
-
Aug 1st, 2011, 09:52 AM
#5
Thread Starter
PowerPoster
Re: WebBrowser control and iframes
oh yeh it does for sure.
The page itself is embedded in an IFRAME I believe.
so close yet so far!
I thought it would be able to access the elements as long as you have the IFRAME document reference, which I believe I have but it does not find anything I tell it, even tho the dev toolbar shows otherwise
-
Aug 1st, 2011, 10:30 AM
#6
Re: WebBrowser control and iframes
I think the dev toolbar might be showing you all the documents inline, whereas the webrowser.Document just gets you the top level document.
This is a guess
Code:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url == webBrowser1.Url)
{
foreach (HtmlWindow window in webBrowser1.Document.Window.Frames)
{
var element = window.Document.GetElementById("demoWrapper");
if (element!= null)
{
Console.WriteLine("Gotcha!");
}
}
}
}
-
Aug 1st, 2011, 10:39 AM
#7
Thread Starter
PowerPoster
Re: WebBrowser control and iframes
good catch about the .Window.Frames.... forgot about that! Will try...
-
Aug 1st, 2011, 02:12 PM
#8
Thread Starter
PowerPoster
Re: WebBrowser control and iframes
hmm. nope 
it says 4 frames but the 3/4th frame throws an unauthorised exception.
-
Aug 1st, 2011, 02:43 PM
#9
Re: WebBrowser control and iframes
How do you feel about posting (or PMing) the url?
-
Aug 1st, 2011, 03:06 PM
#10
Thread Starter
PowerPoster
Re: WebBrowser control and iframes
would feel uncomfortable either way! lol.
its a private internal site which is scattered across the globe and due to internal circumstances, this is the last resort I have of getting the required data from the forms programmatically
-
Mar 28th, 2014, 01:25 AM
#11
New Member
Re: WebBrowser control and iframes
Hi, I'm facing issue in fetching the links (or) get the controls inside IFrame. Can someone suggest me solution.
Thanks inadvance for your response.
Last edited by PoornimaKamal; Apr 4th, 2014 at 07:04 AM.
Reason: addition
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|