Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何单击浏览器并输入文本框?_C#_Wpf - Fatal编程技术网

C# 如何单击浏览器并输入文本框?

C# 如何单击浏览器并输入文本框?,c#,wpf,C#,Wpf,我知道在windows窗体中,使用getelementbyid可以轻松地单击带有ID或其他任何内容的按钮、输入文本框字符串等。但在WPF我什么也找不到。我知道如何将源代码转换为字符串,但我无法单击。你知道这是怎么做到的,甚至是可能的吗?我可以从source+regex获取ID列表。还是有什么东西我可以简单地列出?需要这样的东西: HtmlElement button = webBrowser1.Document.GetElementById("lButtonSearch"); button.Cl

我知道在windows窗体中,使用getelementbyid可以轻松地单击带有ID或其他任何内容的按钮、输入文本框字符串等。但在WPF我什么也找不到。我知道如何将源代码转换为字符串,但我无法单击。你知道这是怎么做到的,甚至是可能的吗?我可以从source+regex获取ID列表。还是有什么东西我可以简单地列出?需要这样的东西:

HtmlElement button = webBrowser1.Document.GetElementById("lButtonSearch");
button.Click += new HtmlElementEventHandler(GotoSearchPage);
我可以这样做,但下一步,如何显示它

 System.Windows.Forms.WebBrowser weba = newSystem.Windows.Forms.WebBrowser();
 weba.Navigate(new Uri("www.google.com"));
 string testowo = "btnI";
 System.Windows.Forms.HtmlElement htmlElement = weba.Document.GetElementById(testowo);   
 htmlElement.InvokeMember("click");
现在如何将其转换为显示让我们假设WebBrowser id为=browserwindows

browserwindow=weba
行不通

试试这个:

var doc = webBrowser1.Document as IHTMLDocument2;
var button = doc.all.OfType<IHTMLInputElement>().FirstOrDefault(b => b.name == "btnG");

if(button != null)
{
    ((IHTMLElement)button).click();
}
var doc=webBrowser1.以IHTMLDocument2的形式记录;
var button=doc.all.OfType().FirstOrDefault(b=>b.name==“btnG”);
如果(按钮!=null)
{
((IHTMLElement)按钮)。单击();
}

如果你想从表单切换到WPF,为什么要依赖于
System.Windows.Forms
(…
WebBrowser
HtmleElement
)?因为我不知道有什么方法可以像Document这样做。WPFSee中的GetElementById(testowo)相关:FillField是工作的,但如果按钮没有id,怎么办,只有名称?:)我给了你一个进入MSHTML类型世界的起点,我不打算在银盘上为你提供任何微小的信息。阅读文档,使用文档化的接口-您将发现一些可能匹配的接口,允许您检查名称。