本文介绍了如何在WebBrowser控件点击一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,使用code和没有用户输入的,怎么会,我有我的程序点击谷歌搜索按钮(假设我已经弥漫在搜索框中日上午在google.com)
解决方案
webBrowser.Navigate(http://www.google.com);
如果你有一个 ID
使用:
webBrowser1.Document.GetElementById(ID)InvokeMember(点击)。
如果您有标签名
使用
webBrowser.Navigate(http://www.google.com);
在Web浏览器DocumentCompleted事件
的HtmlElement的TextElement = webBrowser.Document.All.GetElementsByName(Q)[0];
textElement.SetAttribute(价值,你要搜索的文本);
的HtmlElement btnElement = webBrowser.Document.All.GetElementsByName(btnG)[0];
btnElement.InvokeMember(点击);
如果您有名称类
使用:
HtmlElementCollection classButton = webBrowser1.Document.All;
的foreach(在classButton的HtmlElement元素)
{
如果(element.GetAttribute(类名)==按钮)
{
element.InvokeMember(点击);
}
}
有关在文本框添加文本
搜索google.com,使用:
webBrowser1.Document.GetElementById(gs_tti0)的InnerText =Hello World的。
For example, using code and no user input, how would I have my program click the "Search" button on google (assuming I've already filled in the search box and am at google.com)
解决方案
webBrowser.Navigate("http://www.google.com");
If you have an ID
use this:
webBrowser1.Document.GetElementById("id").InvokeMember("click");
If you have TagName
use this
webBrowser.Navigate("http://www.google.com");
In Web Browser DocumentCompleted event
HtmlElement textElement = webBrowser.Document.All.GetElementsByName("q")[0];
textElement.SetAttribute("value", "your text to search");
HtmlElement btnElement = webBrowser.Document.All.GetElementsByName("btnG")[0];
btnElement.InvokeMember("click");
If you have name Class
use this:
HtmlElementCollection classButton = webBrowser1.Document.All;
foreach (HtmlElement element in classButton)
{
if (element.GetAttribute("className") == "button")
{
element.InvokeMember("click");
}
}
For adding text in a TextBox
to search google.com, use this:
webBrowser1.Document.GetElementById("gs_tti0").InnerText = "hello world";
这篇关于如何在WebBrowser控件点击一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!