c# - 为什么 HtmlElement 的 GetAttribute() 方法返回 "mshtml.HTMLInputElementClass"而不是属性的值?

标签 c# browser

当我尝试获取时,为什么 HtmlElementGetAttribute() 方法返回 mshtml.HTMLInputElementClass 而不是属性的值表单的 action 属性的值?

HtmlElementCollection elements = webBrowser1.Document.Forms;
   foreach (HtmlElement element in elements)
        MessageBox.Show(element.GetAttribute("action") + "");

最佳答案

这似乎是一个 IE 错误。

这是一个解决方案:添加对 Microsoft.mshtml 的引用,然后:

if(element.GetAttribute("action").Equals("mshtml.HTMLInputElementClass"))
{
    mshtml.IHTMLFormElement iForm = (mshtml.IHTMLFormElement)element.DomElement; 
    string action = iForm.action;
}

希望这有帮助:)

关于c# - 为什么 HtmlElement 的 GetAttribute() 方法返回 "mshtml.HTMLInputElementClass"而不是属性的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3805226/

相关文章:

c# - 在 C# 中获取对类中某个类型的所有对象的引用

c# - ASP.NET Core AWS 无服务器和 CORS

c# - 连接 Entity Framework 中的两个表

c# - WebBrowser 控件检查域

google-chrome - PowerShell,如何在现有的浏览器选项卡中打开URL?

php - Web 浏览器如何请求和接收网页?

javascript - 从 webapp 运行外部程序

c# - 如何使用 MTOM 将 vb6 中带有图像附件的 soap 发送到 c# 中的 Web 服务?

search - 什么是 "friendly URL"?

c# - 发布期间未复制数据库文件,因此安装的应用程序抛出异常