Home>

C # IE operation I want to operate a frame-divided page.

Development environment: Visual Studio 2017
OS: Windows 7

However, there is a screen for entering the ID and password for the login screen in "auth1.html" in the main page, and it is not possible to obtain or enter.
webbrowser is not thinking because it can not connect the specified page due to IE7.
I'm trying to run IE with the following source to start IE, but

Error location: var window = doc.frames.item (ref x) as mshtml.HTMLWindow2;
Error content: System.InvalidCastException:'The specified cast is not valid.'

I get the above error.
I would like to know the solutions.
I think this is a beginner question, thank you.

c # program source contents

var IE = new SHDocVw.InternetExplorer ();
    IE.Visible = true;
    object URL = "specified URL";
    IE.Navigate2 (ref URL);
    IE.Wait ();
    var doc = IE.Document as mshtml.IHTMLDocument2;
    object x = 1;
    var window = doc.frames.item (ref x) as mshtml.HTMLWindow2;
    object url2 = window.location.href;
IE.Navigate2 (ref url2);

`` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` ` `` `` `` `` ``

Main page source

<html>
<head><meta http-equiv = "Content-Type" content = "text/html;charset = utf-8">
    <meta name = "test" content = "test">
    <title>Test</title>
    <meta name = "id" content = "auth">
    <script type = "text/JavaScript">
    <!-
    top.location.target = "_ top";
    if (window.location.target! = "_top") {
        top.location.href = window.location.href;
    }
    var savedPwd = "";
    function onPageUnload () {
        window.name = "";
    }
    window.onunload = onPageUnload;
    //->
    </script>
</head>
<frameset name = "frameMain" rows = "100%, 0%, 0%">
    <frame src = "auth1.html" name = "authFrm" scrolling = "no">
    <frame src = "policyBanner.html" name = "policyBannerFrm" scrolling = "no">
    <frame src = "emptyView4.html" name = "authTgtFrm" scrolling = "no">
</frameset>
</html>

`` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` ` `` `` `` `` ``

auth1.html Child source

div align = "left">
            <div></div>
            <div>
                <div>
                </div>
            </div>
            <div>
                Enter your password to get started:
            </div>
            <div>
                <div>
                    User name:
                </div>
                <div>
                    <input type = "text" name = "userName" value = "" maxlength = "128" autocomplete = "off">
                </div>
            </div>
            <div></div>
            <div>
                <div>
                    password:
                </div>
                <div>
                    <input type = "password" name = "pwd" value = "" maxlength = "63" autocomplete = "off">
                </div>
            </div>
            <div></div>
            <div>
                <div>
                    language:
                </div>
                <div>
                    <select name = "select2">
                        <option>Japanese</option>
                    </select>

`` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` ` `` `` `` `` ``

  • Answer # 1

      

    I don't think webbrowser can connect to the specified page because it is IE7.

    It can be 8 or 11 in the registry. So try using WebBrowser.

    Here is an example of how to operate an element in an iframe using WebBrowser.

    Get elements in iframe with WebBrowser
    http://surferonwww.info/BlogEngine/post/2012/08/10/how-to-get-htmlelements-in-iframe-shown-in-webbrowser.aspx

    I think that

    frame is almost the same. Please try.

    [Postscript]

    See the following article on how to specify the IE version by tampering with the registry.

    IE version of WebBrowser control

    Web Browser Control – Specifying the IE Version
    http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version

    If you search for keywords such as webbrowser ie version, you will find many other useful pages.

    Sometimes you can't expect the client to rewrite the registry on the PC, but I think it's just a matter of making it write when the application starts.