问题描述
嗨!
如何在选择按钮后以编程方式选择按钮?
请参阅以下代码:
公共部分课程表格1:表格
{
public Form1()
{
InitializeComponent();
}
private void buttonNavigate_Click(object sender,EventArgs e)
{
string url = http://www.someurl.com;
webBrowser1.Navigate(url);
while(webBrowser1.ReadyState!= WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName(input);
foreach(元素中的HtmlElement元素)
{
if(ele ment.GetAttribute(type)。Equals(button)&&(element.GetAttribute(value)。Equals(Click Here)))
{
element.InvokeMember(click);
}
//此代码点很有用。使用Java加载新页面我想提供新页面的链接。新页面加载在所需的同一窗口中。以下代码没有点击按钮来加载新页面。
任何帮助都会很棒!
尼克
HtmlElementCollection elements2 = webBrowser1.Document.GetElementsByTagName(input);
foreach(elements2中的HtmlElement element2)
{
if(element2.GetAttribute(type)。Equals(button)&&( element2.GetAttribute(value)。Equals(Click Here 2)))
{
element2.InvokeMember(click);
}
}
}
}
}
}
我想知道为什么HtmlElementCollection不能用于第二个实例?
Hi!
How can I select a button programmatically after already selecting a button?
Please see below code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonNavigate_Click(object sender, EventArgs e)
{
string url = "http://www.someurl.com";
webBrowser1.Navigate(url);
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement element in elements)
{
if (element.GetAttribute("type").Equals("button") && (element.GetAttribute("value").Equals("Click Here")))
{
element.InvokeMember("click");
}
//The code to this point works great. The new page loads using Java I think to provide the link to the new page. The new page loads in the same window which is desirable. The below code does not click a button to load a new page.
Any help would be great!
Nick
HtmlElementCollection elements2 = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement element2 in elements2)
{
if (element2.GetAttribute("type").Equals("button") && (element2.GetAttribute("value").Equals("Click Here 2")))
{
element2.InvokeMember("click");
}
}
}
}
}
}
I'm wondering why the HtmlElementCollection isn't working on the second instance?
这篇关于在C#中重定向网页时如何选择按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!