Avatar of SimonPrice3376
SimonPrice3376
 asked on

Access contents \ HTML of an Iframe using WebBrowser control in WinForms

Hi,

I need to read the innerText \ InnerHTML of an iframe.

I have located the frame that I need using

WebBrowser1.Document.Window.Frames(0).Frames(3).Frames(4)

Open in new window


but, when I go to read the innerText \ innerHtml it returns nothing.

looking at the watch window there it is reading nothing, and other elements in other frames read "" or nothing

Any help on how I should be able to get this information would be very much appreciated.

thanks

Simon
Visual Basic.NET.NET ProgrammingProgrammingC#Microsoft Development

Avatar of undefined
Last Comment
SimonPrice3376

8/22/2022 - Mon
Karrtik Iyer

Would it be possible for you to post a sample source HTML which against which you are executing this code and highlight the inner text that you expect as output?
SimonPrice3376

ASKER
Hi Karrtik,

I will pass what information I can as much as possible in a few minutes for you, as some of this is sensitive data I will have to remove\replace some of the names and variables.

however, using

WebBrowser1.Document.Window.Frames(0).Frames(3).Frames(4).Document.Body.InnerText

Open in new window


gives me html output for the frame, but it does not match what I would get if I did a right click and view source. However, if I put the scraped html into a html file and show it it does show the right data.

But there is information in the original source file (from right click view source) that I need, that isn't in the source code that I am pulling from the code.
SimonPrice3376

ASKER
Actually, having compared the data again, its missing the javascipt variables at the top of the page in the <head> tag which is the only bit that I need.

any suggestions?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Karrtik Iyer

Thanks for the information Simon, sample html source would help. I still analysing to see if I can provide you any solutions or suggestions.
ASKER CERTIFIED SOLUTION
SimonPrice3376

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Karrtik Iyer

Something like below?
javascript
object[] codeString = {"aVariable;"};

Open in new window

In C#
string result = webBrowser1.Document.InvokeScript("eval",codeString);

Open in new window

you can refer to below article on ways to invoke particular functions of javascript.
http://www.codeproject.com/Tips/60924/Using-WebBrowser-Document-InvokeScript-to-mess-aro
Karrtik Iyer

Glad you got it. :-)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SimonPrice3376

ASKER
this wasn't an easy solution as many posts I have looked at on the net found a lot of people saying that it couldn't be done...

this took a lot of inspecting each of the elements and properties of an object....  (painstakingly)