前提・実現したいこと
C# IE操作 フレーム分割されたページを操作したいと考えています。
開発環境:Visual Studio 2017
使用OS:Windows 7
しかし、メインページ内にある「auth1.html」内にログイン画面用のID・passwordを入力する画面があり取得・入力等が出来ていない状況です。
webbrowserはIE7であるのが原因で指定ページを接続できないので考えていません。
IEを起動するという下記のようなソースで実行しようとしていますが、
エラー箇所:var window = doc.frames.item(ref x) as mshtml.HTMLWindow2;
エラー内容:System.InvalidCastException: '指定されたキャストは有効ではありません。'
上記エラーが出てしまいます。
解決策等を教えていただきたいです。
初心者的質問だと思いますがよろしくお願いいたします。
c# プログラム ソース内容
var IE = new SHDocVw.InternetExplorer(); IE.Visible = true; object URL = "指定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);
メインページソース
<html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="テスト" content="テスト"> <title>テスト</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" id="frameMain" rows="100%,0%,0%"> <frame src="auth1.html" name="authFrm" id="authFrm" scrolling="no"> <frame src="policyBanner.html" name="policyBannerFrm" id="policyBannerFrm" scrolling="no"> <frame src="emptyView4.html" name="authTgtFrm" id="authTgtFrm" scrolling="no"> </frameset> </html>
auth1.html 子ソース
div id="login_box" align="left"> <div class="vgap85"></div> <div id="error_box" style="visibility:hidden;"> <div id="error_text"> </div> </div> <div id="admin_reauth_text" style="visibility:hidden;"> 管理を始めるためにパスワードを入力してください: </div> <div id="username_line"> <div class="fieldName"> ユーザ名: </div> <div class="fieldValue"> <input type="text" id="userName" name="userName" value="" maxlength="128" autocomplete="off" style="width: 180px;"> </div> </div> <div class="vgap8"></div> <div id="password_line"> <div class="fieldName"> パスワード: </div> <div class="fieldValue"> <input type="password" name="pwd" value="" maxlength="63" autocomplete="off" style="width: 180px;"> </div> </div> <div class="vgap8"></div> <div id="language_line"> <div class="fieldName"> 言語: </div> <div class="fieldValue"> <select name="select2"> <option>日本語</option> </select>
回答1件
あなたの回答
tips
プレビュー