在C#WPF程序我'尝试设置其上定义一个HTML元素Text
值:设置HTML文本元素值
<input name="tbBName" type="text" id="tbBName" tabindex="1" />
我试过如下:
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)webBrowser1.Document;
mshtml.HTMLInputTextElement tbName = (mshtml.HTMLInputTextElement)doc.getElementsByName("tbBName");
tbName.value = "Test";
但我得到以下异常:
Unable to cast COM object of type 'System.__ComObject' to interface type 'mshtml.HTMLInputTextElement'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3050F520-98B5-11CF-BB82-00AA00BDCE0B}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
我知道它说什么,但我不知道我可以使用哪个对象来访问文本框。
我在做什么错?
谢谢你Oded我会看看这个包。 但我没有一个简单的方法与我正在尝试的代码? – Gpx 2010-05-16 07:03:02
@Gpx - 不确定。我注意到的一件事是你正在得到一个_collection_('getElementsByName'返回一个集合),你试图强制它成为一个单一的元素。尝试选择第一个结果。 – Oded 2010-05-16 07:39:00
On mshtml.HTMLElementCollection collection =(mshtml.HTMLElementCollection)document.getElementsByName(“tbName”); 我得到同样的例外。 – Gpx 2010-05-16 08:00:08