这是在Visual Studio防爆preSS 2012年桌面C#应用程序。
This is for a Desktop C# app in Visual Studio Express 2012.
我使用WebBrowser控件登录到不同的网站但是我无法检索和设置属性为这个特定的网站,登录属性是在其中呼吁由HTML的.asp页。
I am using a webBrowser control to logon to various websites however I am unable to retrieve and set the attributes for this particular website where the logon attributes are in an .asp page which is 'called' by the HTML.
属性本身不通过的getElementById或导航通过HtmlElementCollection出现肉眼可见的。
The attributes themselves do not appear visible via GetElementById or navigation through the HtmlElementCollection.
下面的HTML片段展示了调用login.asp和领域CorporateSignonCorpId和CorporateSignonPassword我正在尝试设置但是居住在login.asp
The HTML snippet below shows the call to login.asp and the fields "CorporateSignonCorpId" and "CorporateSignonPassword" which I am trying to set but which reside in "login.asp"
**Website HTML**
</head>
<frameset rows="*,0">
<frame src="login.asp" id="main" name="main" frameborder="0" noresize="true" scrolling="auto" hidefocus="true" target="_top">
<frame src="hiddenframe.asp" id="data" name="data" frameborder="0" noresize="true" scrolling="auto" hidefocus="true">
<noframes>
**login.asp:**
<!--CRN AND PASSWORD TABLE-->
<table border="0" cellpadding="2" cellspacing=0>
<tr>
<td align="right" nowrap class="header5">Customer Registration Number:</td>
<td valign="top" colspan="2"><font face="sans"><input type="TEXT" name="CorporateSignonCorpId" tabIndex=0 size="16" maxlength="19" AUTOCOMPLETE="OFF" onKeyPress="onFocus:microsoftKeyPress();" onFocus="javascript: strActiveField='CorporateSignonCorpId';"></font></td>
</tr>
<tr>
<td align="right" class="header5">Password:</td>
<td valign="top"><font face="sans"><input type="PASSWORD" name="CorporateSignonPassword" size="16" tabIndex=0 AUTOCOMPLETE="OFF" onKeyPress="javascript:microsoftKeyPress();" onFocus="javascript: strActiveField='CorporateSignonPassword';"></font></td>
</tr>
<tr>
在C#中我如何引用,并设置值的属性CorporateSignonCorpId和CorporateSignonPassword?
How do I reference and set values for the attributes "CorporateSignonCorpId" and "CorporateSignonPassword" in C#?
任何帮助,将AP preciated! thks米克
ANY help would be appreciated!! thks Mick
您可以使用 webBrowser.Document.Window.Frames [主。文件
去内框的文件。对我来说,以下工作:
You can use webBrowser.Document.Window.Frames["main"].Document
to get to the inner frame's document. The following works for me:
private async void MainForm_Load(object sender, EventArgs e)
{
var tcs = new TaskCompletionSource<bool>();
WebBrowserDocumentCompletedEventHandler handler = (s, arg) =>
tcs.TrySetResult(true);
this.webBrowser.DocumentCompleted += handler;
this.webBrowser.Navigate("http://localhost:81/frameset.html");
await tcs.Task;
this.webBrowser.DocumentCompleted -= handler;
var frameDocument = this.webBrowser.Document.Window.Frames["main"].Document;
var element = frameDocument.GetElementById("CorporateSignonCorpId");
MessageBox.Show(element.OuterHtml);
}