am loading a webpage using the webbrowser control, in it there is a form that is generateb by javascript.
when i tried to access th elements in c#, they cannot be found.
the page renders well in a normal browser, but in my winforms app, the form elements are not rendered, i can only see the javascript that generated the form when dubugging
a close solution i found on stack was to cast the webbrowser.document.domdocument
to ihtmldocument
, but i havent been successful with it,
this is what am trying to do
Dim doc As HtmlDocument = DirectCast(wbMain.Document.DomDocument, MSH.IHTMLDocument)
but i get this warning
Runtime errors might occur when converting 'mshtml.IHTMLDocument' to 'System.Windows.Forms.HtmlDocument'.
and whe i ignore and run, i got this error
Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
EDIT A sample javascript
<SCRIPT type=text/javascript>
(function(){
function runElemGen() {
var ElemGenForm = [{"label":"Email:","name":"ElemGen_email_field","oldName":"","value":"","ElemGen":"text"},{"label":"","name":"ElemGensubscribe","oldName":"","value":"Submit","ElemGen":"submit"}];
ElemGenBuildForm({makeDivs: true, arr:ElemGenForm, place:"ElemGen-email-form-"});
}
if (window.addEventListener) {
window.addEventListener("load", runElemGen, false);
} else {
window.attachEvent("onload", runElemGen);
}
})();
</SCRIPT>
can anyone with a solution help