Reputation: 313
If I would use default Visualstudio webBrowser control (IE) i would just write something like this:
textBox3.Text = webBrowser1.Document.GetElementById("mydivid").InnerHtml;
But I'm stubborn to use GeckoFX (Mozilla) and ofcourse it doesn't work. What I found is information that I need to adress "HTMLDocument" not "Document" to pull my desired value. But no example that fit my needs. How to get this innerHTML of this particular element?
--- Response to @Timothy Groote ---
I've read the other topic - there's no example of code with GetElementById
, it's like wide definition, but I need specific one - I cannot read this codeand get clear information what method or property shoueld I use in my app.
I can add that my element is and will be always HTML element, so i don't need to verify that every time with "if".
When I use "the other code" in my app result (instead of innerHTML) was only:
<head></head><body></body>
In "the other code" has also a mistake:
var geckoDomElement = WebBrowser1.Document.DocumentElement;
There's no webBrowser1 control! Only geckoWebBrowser1, neither works!
--- Edit2 ---
I was also thinking about something like that:
textBox3.text = (GeckoHtmlElement)geckoWebBrowser1.Document.GetElementById("mydivid")....
but there's also no "innerHtml"
in
(GeckoHtmlElement)geckoWebBrowser1.Document.DocumentElement
there's no "getElementById".
Upvotes: 1
Views: 2243
Reputation: 313
ANSWER Of course defining variable:
GeckoHtmlElement machcode;
Finding element:
machcode = geckoWebBrowser1.Document.GetHtmlElementById("machinecode");
And finally reading the content:
textBox3.Text = machcode.InnerHtml;
And one important thing was to place code in DocumentComplete event!
Every solutions provided in web were wrong - some point into nonexisting webBrowser1 control, some forget about definition, some throw null exception, some use wrong GetElement instead of GetHtmlElement.
Upvotes: 1
Reputation: 21
If you using Geckofx 45 then its very simple , just try like this....
GeckoHtmlElement testelement = null;
testelement = (GeckoHtmlElement)webBrowser1.Document.GetElementById("test");
string text=testelement .InnerHtml;
if you don't know how to use Geckofx 45 then try this simple tutorial .. How to use or embed Geckofx 45 Webbrowser control into Visual Studio into WinForms Applications
Upvotes: 2