Im creating an IE BHO and trying to access a page that has multiple iframe tags. How to access the text in a span with id="messageText-txt" which is inside a specific iframe with name="isolatedWorkArea" and id="isolatedWorkArea" using mshtml.
I tried the following options but none of them returns me the text. Any idea?
Option 1:
void BrowserEvents_NavigateComplete2(object pDisp, ref object URL)
{
SHDocVw.InternetExplorer currentIEWin = pDisp as SHDocVw.InternetExplorer;
mshtml.IHTMLDocument2 docObject = currentIeWin.Document as IHTMLDocument2;
mshtml.FramesCollection iframesCollection = docObject.frames;
for (int i = 0; i <= iframesCollection.length; i++)
{
mshtml.HTMLDocument iFrameDocObject = iframesCollection.item(i).document as HTMLDocument;
if (iFrameDocObject != null)
{
IHTMLElement spanMessageText = iFrameDocObject.getElementById("messageText-txt");
if (!string.IsNullOrEmpty(spanMessageText.innerHTML))
{
spanText = spanMessageText.innerHTML;
Option 2:
void BrowserEvents_NavigateComplete2(object pDisp, ref object URL)
{
SHDocVw.InternetExplorer currentIEWin = pDisp as SHDocVw.InternetExplorer;
mshtml.IHTMLDocument3 docObject2 = currentIeWin.Document as IHTMLDocument3;
IHTMLElement Iframe = docObject2.getElementById("isolatedWorkArea");
if (Iframe != null)
{
mshtml.HTMLDocument iFrameDocObject = Iframe.document as HTMLDocument;
if (iFrameDocObject != null)
{
IHTMLElement spanMessageText = iFrameDocObject.getElementById("messageText-txt");
if (spanMessageText != null)
{
if (!string.IsNullOrEmpty(spanMessageText.innerHTML))
{
spanText = spanMessageText.innerHTML;
Option 3:
void BrowserEvents_NavigateComplete2(object pDisp, ref object URL)
{
SHDocVw.InternetExplorer currentIEWin = pDisp as SHDocVw.InternetExplorer;
mshtml.IHTMLDocument3 docObject2 = currentIeWin.Document as IHTMLDocument3;
IHTMLElementCollection frames = (IHTMLElementCollection)docObject2.getElementsByTagName("frame");
if (frames != null)
{
foreach (HTMLIFrame frm in frames)
{
if (frm != null)
{
mshtml.HTMLDocument iFrameDocObject = frm.document as HTMLDocument;
if (iFrameDocObject != null)
{
IHTMLElement spanMessageText = iFrameDocObject.getElementById("messageText-txt");
if (spanMessageText != null)
{
if (!string.IsNullOrEmpty(spanMessageText.innerHTML))
{
spanText = spanMessageText.innerHTML;