getElementById en el elemento dentro de un iframe
Mi código actual funciona en elementos fuera de un iframe. ¿Cómo debo acercarme a buscar elementos dentro de un iframe usando getElementById? Mi objetivo final es escribir texto dentro del<body id="tinymce"><p>...</p></body>
etiquetas No estoy usando un control webBrowser - esto es para una instancia externa de iexplore
Ejemplo HTML
Ejemplo de código
foreach (InternetExplorer ie in new ShellWindowsClass())
{
if (ie.LocationURL.ToString().IndexOf("intranet_site_url") != -1)
{
IWebBrowserApp wb = (IWebBrowserApp)ie;
while (wb.Busy) { Thread.Sleep(100); }
HTMLDocument document = ((HTMLDocument)wb.Document);
// FETCH BY ID
IHTMLElement element;
HTMLInputElementClass hitem;
element = document.getElementById("tinymce");
hitem = (HTMLInputElementClass)element;
hitem.value = first_name;
// FETCH BY ID in IFRAME
IHTMLFramesCollection2 hframes = document.frames;
for (int i = 0; i < hframes.length; i++)
{
object ref_index = i;
IHTMLWindow2 currentFrame = (IHTMLWindow2)hframes.item(ref ref_index);
if (currentFrame != null)
{
MessageBox.Show(currentFrame.name);
// what to do from here?
}
else
MessageBox.Show("Null");
}
}
}
- actualizar idea ¿Posibilidad de adaptar mi idea a continuación?
if (currentFrame != null)
{
MessageBox.Show(currentFrame.name);
HTMLDocument document_sub = ((HTMLDocument)currentFrame.document);
IHTMLElement element_sub;
HTMLInputElementClass hitem_sub;
element_sub = (document_sub.getElementById("tinymce"));
hitem_sub = (HTMLInputElementClass)element_sub;
try
{
hitem_sub.value = first_name;
// the above will produce...
// InvalidCastException: Unable to cast COM object of type 'mshtml.HTMLBodyCLass' to class type 'mshtml.HTMLInputElementClass'
}
catch { }
}