且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C#在Window窗体中获取IFRAME控件

更新时间:2023-12-06 12:34:04

Y你可以尝试使用下面的代码:



 ContentPlaceHolder holder =(ContentPlaceHolder) this .CurrentMaster.FindControl(  xyzlogin); 

HtmlControl control1 =(HtmlControl)holder.FindControl( Email) ;
HtmlControl control2 =(HtmlControl)holder.FindControl( Passwd);
HtmlControl control3 =(HtmlControl)holder.FindControl( Signin);


webbrowser控件的文档对象有一个名为window object的属性,这将引用iframe控件



如果您的webbrowser控件名称是webBrCtrl,那么下面的行应该为您提供在webbrowser控件中加载的HTML文档中的iFrame集合。







webBrCtrl.Document.Window.Frames





希望这能解决你的问题问题

I am using the Webbrowser control(IE object) in VS 2008 C# Express to automate the
navigation of pages on a partner''s web site. The first page contains
an <IFRAME> element:

<iframe style=''width:40; height:40''; align=''center'' marginwidth=''0''
marginheight=''0''
scrolling=''no'' frameborder=''0'' id=''xyzlogin'' name=''xyzlogin''
src=''https://www.xyzcorp.com/accounts/ServiceLogin''>
</iframe>

Within that frame I need to access these three elements:

<input type="text" name="Email" value="" class="xyz le val" id="Email"
size="18">
<input type="password" name="Passwd" class="xyz le val" id="Passwd"
size="18">
<input type="submit" name="null" value="Sign in" class="xyz le button"

so I to automate programmatically this login: 1)enter the user ID and password, and 2)click
the ''Sign in'' button.


can someone provide me code sample how to resolve this.

You can try using the below code:

ContentPlaceHolder holder = (ContentPlaceHolder)this.CurrentMaster.FindControl("xyzlogin");

HtmlControl control1 = (HtmlControl)holder.FindControl("Email");
HtmlControl control2 = (HtmlControl)holder.FindControl("Passwd");
HtmlControl control3 = (HtmlControl)holder.FindControl("Signin");


the document object of the webbrowser control has a property called window object, this would give reference to the iframe controls

if your webbrowser control name is webBrCtrl then the below line should give you the collections of iFrames in the HTML document that is loaded in the webbrowser control.



webBrCtrl.Document.Window.Frames


hope this solves your problem.