C# 如何从程序发送 ENTER?
我是初学者,我编写了这段代码,但无法从 C# 上的 webbrowser 组件发送 ENTER 单击:
private void start_submit_Click(object sender, EventArgs e)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("settings.xml");
foreach (System.Xml.XmlNode node in xdoc.SelectNodes("//site"))
{
foreach (System.Xml.XmlNode child in node)
{
if (child.Attributes["todo"].Value.ToString() == "navigate")
{
navigate(url_string);
}
else if (child.Attributes["todo"].Value.ToString() == "checkbox")
{
HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("input");
HtmlElement ele0 = es[1];
ele0.SetAttribute("checked", "true");
}
else if (child.Attributes["todo"].Value.ToString() == "pressbutton")
{
HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("input");
if (es != null && es.Count != 0)
{
HtmlElement ele = es[5];
ele.ScrollIntoView(true);
ele.Focus();
SendKeys.Send("{ENTER}");
}
}
else if (child.Attributes["todo"].Value.ToString() == "wait")
{
MessageBox.Show("waiting...");
}
}
}
}
和 settings.xml 文件:
<?xml version="1.0" encoding="utf-8" ?>
<data>
<site num="1" name="http://www.clantemplates.com" pr="5">
<step num="1" todo="navigate" value_todo="http://www.clantemplates.com/forums/register.php" value_2_todo="none">navigating</step>
<step num="2" todo="checkbox" value_todo="true" value_2_todo="8">checking checkbox</step>
<step num="3" todo="pressbutton" value_todo="enter" value_2_todo="9">pressing button</step>
<step num="4" todo="wait" value_todo="" value_2_todo="">waiting for other click</step>
</site>
</data>
没有这一部分 ENTER 会成功发送
else if (child.Attributes["todo"].Value.ToString() == "wait")
{
MessageBox.Show("waiting...");
}
- 不知道
如何解决?
谢谢!
i am beginer and i write this code and can't send ENTER click from webbrowser component on C#:
private void start_submit_Click(object sender, EventArgs e)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("settings.xml");
foreach (System.Xml.XmlNode node in xdoc.SelectNodes("//site"))
{
foreach (System.Xml.XmlNode child in node)
{
if (child.Attributes["todo"].Value.ToString() == "navigate")
{
navigate(url_string);
}
else if (child.Attributes["todo"].Value.ToString() == "checkbox")
{
HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("input");
HtmlElement ele0 = es[1];
ele0.SetAttribute("checked", "true");
}
else if (child.Attributes["todo"].Value.ToString() == "pressbutton")
{
HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("input");
if (es != null && es.Count != 0)
{
HtmlElement ele = es[5];
ele.ScrollIntoView(true);
ele.Focus();
SendKeys.Send("{ENTER}");
}
}
else if (child.Attributes["todo"].Value.ToString() == "wait")
{
MessageBox.Show("waiting...");
}
}
}
}
and settings.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<data>
<site num="1" name="http://www.clantemplates.com" pr="5">
<step num="1" todo="navigate" value_todo="http://www.clantemplates.com/forums/register.php" value_2_todo="none">navigating</step>
<step num="2" todo="checkbox" value_todo="true" value_2_todo="8">checking checkbox</step>
<step num="3" todo="pressbutton" value_todo="enter" value_2_todo="9">pressing button</step>
<step num="4" todo="wait" value_todo="" value_2_todo="">waiting for other click</step>
</site>
</data>
without this piece ENTER sends succesfully
else if (child.Attributes["todo"].Value.ToString() == "wait")
{
MessageBox.Show("waiting...");
}
with piece - no
how to solve?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了,我这样做:
Solved, i do that with: