I am using a Webbrowser control to sign into Hotmail. Then once it is signed in then I'll just use this navigate code to open the inbox:

I think that the problem is that the actual inbox(mail window) is within an iframe. I have to figure out how to call within the iframe.

If you can goto hotmail and sign in and you'll see once your in the inbox when you view source it isn't the inbox's source but then when you right click then goto this frame then view the source to the frame it is.

WebBrowser1.Navigate("http://g.live.com/9uxp9en-us/hdr_main4??su=http://shared.live.com/Live.Mail")

Now my problem from this point on is how to open the very first email. I have tried using my click link code that I have, I have tried everything. I have spent 3 days searching the net and trying different stuff. I know that it's 100 percent possible. I am praying that someone that is a Webbrowser Control Genius can help me!

Maybe this can help, this is some html to the page where the inbox is. This isn't the inbox's source but thought that this could help. This is what is calling to the iframe :

function loadIM(q)
    {
        if (gLoadIM &&
            (!q || q.indexOf('nwi=1') < 0)) 
        {
            gLoadIM = false;
            var win = getUiWindow(), loc = win.location;
            gUIFrameBaseUrl = loc.host;
            var imFrame = document.getElementById("IMFrame");
            if (imFrame)
            {
                imFrame.src = [loc.protocol, "//", gUIFrameBaseUrl, "/im/pages/im.aspx"].join("");
            }
            imFrame = null;
        }
   }


    function uiFrameLoad()
    {
        //
        try
        {
            if(!isPersistenceInline)
            {
                document.title = window.frames[0].document.title;
            }

            if (gLoadIM)
            {
                loadIM(getUiWindow().location.search); 
            }

        }
        catch(e)
        {
        }
    }
    function beforeUnloadHandler()
    {
        try
        {
            var frameUrl = getUiWindow().document.location.href;
            document.cookie = "afu=" + escape(frameUrl) + ";path=/;domain=.mail.live.com;";
        }
        catch(e)
        {
        }
    }
    function getUiFrame()
    {
        return document.getElementById("UIFrame");
    }
    function getUiFrameOrBody()
    {
        return isPersistenceInline ? document.body : getUiFrame();
    }
    function getUiWindow()
    {
        return isPersistenceInline ? window : getUiFrame().contentWindow;
    }
    function makePersistenceStandalone()
    {
        isPersistenceInline = false;

        var imFrame = document.getElementById("IMFrame");
        if(imFrame && imFrame.contentWindow.updateUIFrameRef)
        {
            imFrame.contentWindow.updateUIFrameRef();
        }

    }
    function redirectToLandingPage()
    {
        if(!isPersistenceInline)
        {
            getUiFrame().src = 'http\x3a\x2f\x2fbl136w.blu136.mail.live.com\x2fmail\x2fInboxLight.aspx\x3fFolderID\x3d00000000-0000-0000-0000-000000000001\x26InboxSortAscending\x3dFalse\x26InboxSortBy\x3dDate\x26n\x3d74874372';
        }
    }
</script>

</head>
<body style="padding:0;margin:0;overflow:visible;height:100%;width:100%;position:absolute;" onbeforeunload="beforeUnloadHandler()">

    
<div id="appDiv" style="position:absolute;height:100%;width:100%;">
    <iframe id="UIFrame" name="UIFrame"  src="" onload="uiFrameLoad();"
        frameborder="0"
        width="100%"
        height="100%"
        marginheight="0"
        marginwidth="0">
    </iframe>

    <iframe id="IMFrame" frameborder="0" width="0" height="0" src=""></iframe>

</div>

This is the source to inbox which is within the iframe:

<table class="InboxTable" cellspacing="0" cellpadding="0"><colgroup><col class="CheckBoxCol"/><col class="IconCol"/><col class="FromCol"/><col class="ImportanceCol"/><col class="AttachmentCol"/><col class="SubjectCol"/><col class="DateCol"/></colgroup><tbody onclick="return Control.invoke('MessageList', '_onBodyClick', event);" ondblclick="return Control.invoke('MessageList', '_onDblClick', event);"><tr  id="fe43dd91-f643-11de-aaa1-00215ad7dbba" msg="msg" mad="40|0|8CC5867E5DB5630||" ><td class="Chk" name="msgChkCell" unselectable="on"><input type="checkbox" name="msgChk"  title="Select message"/></td><td class="Ico"><img src="./clear.gif" class="i_read" alt="Read"/></td><td class="Frm"><a>Dailymotion Notifications</a></td><td class="Imp"></td><td class="Att"></td><td class="Sbj"><a href="javascript:;">Dailymotion registration confirmation&#x200f;</a></td><td class="Dat">Yesterday</td></tr><tr  class="InboxContentItemUnread" id="593d12f7-5ca0-4901-b83b-49dc4dbf5cbe" msg="msg" mad="10|0|8CC4F5C59B09E90||" ><td class="Chk" name="msgChkCell" unselectable="on"><input type="checkbox" name="msgChk"  title="Select message"/></td><td class="Ico"><img src="./clear.gif" class="i_new" alt="Unread"/></td><td class="Frm"><a>Windows Live Hotmail Member Services</a></td><td class="Imp"></td><td class="Att"></td><td class="Sbj"><a href="javascript:;">Getting started with Windows Live Hotmail&#x200f;</a></td><td class="Dat">12/20/09</td></tr></tbody></table></div>

        </div>
        <div class="PaginationContainer BorderTop">
            <div class="PageNavigationMsgRange">2 messages</div><div class="PageNavigation FloatRight" onclick="return Control.invoke('MessageList', '_onNavClick', event);"><ul><li><div >Page</div></li><li pnCur="1" pnAm="fe43dd91-f643-11de-aaa1-00215ad7dbba" pnAd="2009-12-31T19:38:01.363Z" pnDir="FirstPage" pnMid="2" pnSkip="0"><a href="javascript:;" title="Go to page 1"  class="PrimaryTextColor BoldText">1</a></li><li ><div><img class="PageNavigationPrev" src="" alt="Previous page"/></div></li><li ><div><img class="PageNavigationNext" src="" alt="Next page"/></div></li></ul></div>

        </div>
    </div>
</div>
            </div>

        </div>
        <div id="readingPaneSplitter"  class="SplitterBar SplitterBarHidden"></div>
        <div id="readingPaneSplitPane"  class="ReadingPaneSplitPane ReadingPaneSplitPaneFull ReadingPaneSplitPaneHidden">
            <div id="actionBar" class="ActionBar BorderBottom" style="visibility:hidden;" onclick="return Control.invokeStatic('Toolbar', 'onclick', event, Control.lookup(event.srcElement, 'aId'));">
                <div class="Toolbar">
		            <ul>
		                
<li aId="ReplyButton" class="ToolbarItem "  style="display:none;"><a  title="Reply (Ctrl+R)" href="javascript:;" id="ReplyButton"  onclick="PerfRecorder.startTimer(false, 'COR');">
    <span class="Label">Reply</span></a></li>

    
<li aId="ReplyAllButton" class="ToolbarItem "  style="display:none;"><a  title="Reply all (Ctrl+Shift+R)" href="javascript:;" id="ReplyAllButton"  onclick="PerfRecorder.startTimer(false, 'COR');">
    <span class="Label">Reply all</span></a></li>
    
<li aId="ForwardButton" class="ToolbarItem "  style="display:none;"><a  title="Forward (Ctrl+Shift+F)" href="javascript:;" id="ForwardButton"  onclick="PerfRecorder.startTimer(false, 'COR');">
    <span class="Label">Forward</span></a></li>
<li id="BeforeNextPrevPipe" class="ToolbarItem"  style="display:none;"><span class="ToolbarPipe">|</span></li>
    
<li aId="NextButton" class="ToolbarItem ToolbarItemThinRightPadding" style="display:none;"><a title="Next message (Ctrl+.)" href="javascript:;"  id="NextButton"><img src="./clear.gif" class="i_next" title="Next message (Ctrl+.)" alt="Next message"/></a></li>
    
<li aId="PreviousButton" class="ToolbarItem ToolbarItemThinLeftPadding" style="display:none;"><a title="Previous message (Ctrl+,)" href="javascript:;"  id="PreviousButton"><img src="./clear.gif" class="i_previous" title="Previous message (Ctrl+,)" alt="Previous message"/></a></li>

                        <li class="ToolbarItem ToolbarItemLast FloatRight CloseButton"><a aId="CloseButton" href="javascript:;"><img src="./clear.gif" class="glyph_close_rest" title="Click here to close the full message view (Esc)" alt="Click here to close the full message view"/></a></li>
                        <li class="ToolbarItem ToolbarItemLast FloatRight FullViewButton"><a aId="FullViewButton" href="javascript:;"><span class="Label">Full view</span></a></li>

I didn't post all the code I just posted what I though was important.

Who every can help me with this, I will do anything for you lol. I would love to give you something for your help. This is how much this means to me and I have just gave it all the sweat and blood that I can :)

Thank you so very much and God Bless,

Thomas

Dani AI

Generated

spotted the key issue: the message list is rendered inside an iframe, so the WinForms WebBrowser must target that frame's DOM (or navigate directly to the frame URL) before any element clicks will work. 's suggestion to provide a small repro is useful—isolating a minimal page that contains the same iframe makes it much easier to test frame access and timing.

Practical approach (summary):

  • Wait for the WebBrowser DocumentCompleted event for the page (and for the frame URL if necessary).
  • Get the iframe's HtmlWindow from the top document's Window.Frames collection and obtain that frame's HtmlDocument.
  • Locate the subject link (the clickable <a> inside the message row) in the frame document and invoke its click handler with HtmlElement.InvokeMember("click") or HtmlElement.RaiseEvent("onclick").
  • If access to the frame Document fails (null or COM/security exception), it is almost certainly a cross-origin restriction; fall back to navigating the WebBrowser directly to the inbox/frame URL after login or use an in-frame script call if same-origin.

Example VB.NET pattern (adapt to the actual selectors used in the inbox):

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) _
    Handles WebBrowser1.DocumentCompleted

    If WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Then Return

    Dim topWin = WebBrowser1.Document?.Window
    If topWin Is Nothing Then Return

    Dim frameWin As HtmlWindow = Nothing
    For Each f As HtmlWindow In topWin.Frames
        If String.Equals(f.Name, "UIFrame", StringComparison.OrdinalIgnoreCase) Then
            frameWin = f : Exit For
        End If
    Next

    If frameWin Is Nothing AndAlso topWin.Frames.Count > 0 Then frameWin = topWin.Frames(0)

    Try
        Dim fDoc = frameWin?.Document
        If fDoc IsNot Nothing Then
            For Each a As HtmlElement In fDoc.GetElementsByTagName("a")
                If a.Parent IsNot Nothing AndAlso a.Parent.GetAttribute("class").IndexOf("Sbj", StringComparison.OrdinalIgnoreCase) >= 0 Then
                    a.Focus()
                    a.RaiseEvent("onclick")
                    a.InvokeMember("click")
                    Exit For
                End If
            Next
        End If
    Catch ex As Exception
        ' likely same-origin or timing issue; handle fallback here
    End Try

End Sub

Troubleshooting tips:

  • Use the DocumentCompleted event's Url property to detect when the iframe URL finishes loading; frame content may arrive after the top-level DocumentCompleted.
  • If accessing the frame Document throws or stays Nothing, check for same-origin limitations (different host/subdomain). The managed DOM exposes frame metadata but disallows cross-domain DOM access; in that case navigate the control to the frame URL (cookies from the login session will normally carry over) or run an in-page script only if the frame is same-origin. See the Microsoft guidance on accessing frames in the managed DOM and the HTML same-origin policy for details.

References: Microsoft: Accessing frames in the managed HTML DOM and invoking element members (Accessing frames, InvokeMember / unexposed members); same-origin policy explanation (MDN Same-origin policy).

Recommended Answers

All 3 Replies

Upload a sample project demonstrating the problem. It is a lot of work to get a test scenario set up to answer your question.

Not really because it's just a webbrowser control. All i'm asking is when you just simply login to hotmail and goto into the inbox how to actually open up the first email.

I really don't need any project file file because all the code in the project will not help at all with this. This is why I have posted all the html with it.

It blows my mind I can't find anyone at all that knows enough about webbrowser controls to help me.

I am so upset :(

Can you please help me, I'll do anything my friend, anything.

If it will help maybe though here is the code I have so far,

WebBrowser1.Navigate("http://www.hotmail.com", Nothing, Nothing, Nothing)

        Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
            Application.DoEvents()
        Loop

        If Not TextExists("Hotmail", False) And TextExists("Sign in", False) Then GoTo start

        If TextExists("Sign in with a different account", False) Then
            clicklink("Sign in with a different account")
            Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
                Application.DoEvents()
            Loop
            Delay(3)
        End If

        Me.WebBrowser1.Document.GetElementById("i0116").InnerText = (emailused) : Delay(1)
        Me.WebBrowser1.Document.GetElementById("i0118").InnerText = (pwused) : Delay(1)

        Me.WebBrowser1.Document.GetElementById("i0201").InvokeMember("click") : Delay(2)
        Me.WebBrowser1.Document.GetElementById("SI").InvokeMember("click") : Delay(1)

        Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
            Application.DoEvents()
        Loop

        Delay(3)

        WebBrowser1.Navigate("http://g.live.com/9uxp9en-us/hdr_main4??su=http://shared.live.com/Live.Mail")

        Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
            Application.DoEvents()
        Loop
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.