如何使用C#在Window窗体中获取IFRAME控件 [英] how to get IFRAME controls in Window forms using C#
问题描述
我在VS 2008 C#Express中使用Webbrowser控件(IE对象)来自动化合作伙伴网站上页面的
导航。第一页包含
an< IFRAME>元素:
< iframe style =''width:40;高度:40’ ; align =''center''marginwidth =''0''
marginheight =''0''
scrolling =''no''frameborder =''0' 'id =''xyzlogin''name =''xyzlogin''
src =''https://www.xyzcorp.com/accounts/ServiceLogin''>
< / iframe>
在该框架内,我需要访问这三个元素:
< input type =textname =Emailvalue =class =xyz le valid =电子邮件
size =18>
< input type =passwordname =Passwdclass =xyz le valid =Passwd
size =18>
< input type =submitname =nullvalue =登录class =xyz le button
所以我以编程方式自动执行此登录: 1)输入用户名和密码,2)点击
''登录''按钮。
有人可以为我提供代码示例如何解决此问题。
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.
这篇关于如何使用C#在Window窗体中获取IFRAME控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!