Sao*_*obi 2 html c# dom mshtml
在C#中,我设法从InternetExplorer对象获取整个HTMLDocumentClass(导航到某个URL).
但是,在Visual Studio 2008的调试模式下,此特定URL的HTMLDocumentClass的内容是MASSIVE,包括activeElement,alinkColor,all,applets,charset,childNodes等属性等.
该页面中有一个按钮,我希望将其更改为"Clicked".但我不知道如何找到该按钮的名称/ ID /标签.有一个简单的教程,使用如下语句:
HTMLInputElement button =
(HTMLInputElement)theDoc.getElementById("Button1");
button.click();
Run Code Online (Sandbox Code Playgroud)
但我的网址结构比这复杂100倍.
假设网址是yahoo.com,我想"点击"网络搜索按钮.
有任何系统的方式来解决这个问题?
假设我的WebBrowser控件位于Yahoo.搜索按钮的ID是"searchsubmit"
使用Windows.Forms.HtmlDocument
HtmlElement button = (HtmlElement)htmlDoc.GetElementById("searchsubmit");
button.InvokeMember("click");
Run Code Online (Sandbox Code Playgroud)
如果使用mshtml和HTMLInputElement
HTMLDocument htmlDoc = new HTMLDocumentClass();
htmlDoc = (HTMLDocument)axWebBrowser1.Document;
//find the search text box..
HTMLInputElement searchTextBox = (HTMLInputElement)htmlDoc.all.item("p", 0);
searchTextBox.value = "Stack Overflow";
//find the button
HTMLInputElement searchButton = (HTMLInputElement)htmlDoc.all.item("searchsubmit", 0);
searchButton.click();
Run Code Online (Sandbox Code Playgroud)
如果查看Yahoo源代码,您会看到搜索文本框位于多个div中.htmlDoc.all.item负责处理它.
| 归档时间: |
|
| 查看次数: |
26642 次 |
| 最近记录: |