webbrowser 控件 SetAttribute 不以编程方式响应
我有应用程序,我需要以编程方式将文本添加到某些字段,它在大多数页面中都有效,但在 www.google.com 中,当我尝试但要搜索值时,它不起作用,直到我单击文本区域,然后出现的值
是有什么方法可以解决
我的代码:
HtmlElementCollection el = webBrowser1.Document.All;
foreach (HtmlElement H in el)
{
if (H.GetAttribute("type").Equals("text") )
H.SetAttribute("value", sendtext);
}
我尝试以编程方式单击它,
object obj = H.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]);
但它不起作用
i have application and i need to add text programmatically to some fields it works in most pages but in www.google.com when i try to but value to search, it did not work until i clicked on the text area then the value appear
is there any way to get around this
my code:
HtmlElementCollection el = webBrowser1.Document.All;
foreach (HtmlElement H in el)
{
if (H.GetAttribute("type").Equals("text") )
H.SetAttribute("value", sendtext);
}
i tried to click on it programmatically
object obj = H.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]);
also it does not work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
项目 + 添加引用,浏览选项卡并选择 c:\windows\system32\mshtml.tlb(早期 Windows 版本上为 .dll)。这使您可以访问 DomElement 属性返回的本机 COM 接口。因此,您可以像这样干净地编写代码:
或者您可以使用 HtmlElement.InvokeMember() 方法稍微不那么干净地编写代码:
使用此技术运行 google 查询的示例表单:
Project + Add Reference, Browse tab and select c:\windows\system32\mshtml.tlb (.dll on earlier Windows versions). This gives you access to the native COM interface that the DomElement property returns. So you can write your code cleanly like this:
Or you can do it a bit less cleanly with the HtmlElement.InvokeMember() method:
A sample form that runs a google query using this technique: