如何获取WPF中webbrowser控件的输入框的值? [英] How to get the value of an input box of the webbrowser control in WPF?

查看:557
本文介绍了如何获取WPF中webbrowser控件的输入框的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I added Microsoft.mshtml as a reference to my project and came this far:

我添加了Microsoft.mshtml作为对我的项目的引用, .IHTMLDocument2)webbrowser.Document;
string username = document.all [username]。GetAttribute(value);

mshtml.IHTMLDocument2 document = (mshtml.IHTMLDocument2)webbrowser.Document; string username = document.all["username"].GetAttribute("value");

但第二行不起作用。它说

but the 2nd line doesn't work. It says


错误CS0021:无法将[]的索引应用于
类型的表达式mshtml.IHTMLElementCollection ''

当鼠标悬停在全部上时。

when hovering over "all". How do I access the elements in all?

推荐答案

试试这个:

var document = (IHTMLDocument3) webbrowser.Document;
var value =
    document.getElementsByName("username")
            .OfType<IHTMLElement>()
            .Select(element => element.getAttribute("value"))
            .FirstOrDefault();

这篇关于如何获取WPF中webbrowser控件的输入框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆