我是GeckoBrowser的新手。问题出在我的SetText
方法中:
void SetText(string attribute, string attName, string value)
{
// Get a collection of all the tags with name "input";
HtmlElementCollection tagsCollection =
geckoWebBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement currentTag in tagsCollection)
{
// If the attribute of the current tag has the name attName
if (currentTag.GetAttribute(attribute).Equals(attName))
{
// Then set its attribute "value".
currentTag.SetAttribute("value", value);
currentTag.Focus();
}
}
}
但我在这一行上收到错误:
HtmlElementCollection tagsCollection =
geckoWebBrowser1.Document.GetElementsByTagName("input");
错误是:
Cannot implicitly convert type 'Skybound.Gecko.GeckoElementCollection' to 'System.Windows.Forms.HtmlElementCollection'
任何想法如何解决这个问题?
答案 0 :(得分:3)
GetElementsByTagName
上的GeckoDocument
方法未返回HtmlElementCollection
,它返回GeckoElementCollection
(其中包含GeckoElement
s,而不是HtmlElement
{1}} S)。
所以你需要这样的东西(未经测试):
void SetText(string attribute, string attName, string value)
{
// Get a collection of all the tags with name "input";
GeckoElementCollection tagsCollection = geckoWebBrowser1.Document.GetElementsByTagName("input");
foreach (GeckoElement currentTag in tagsCollection)
{
// If the attribute of the current tag has the name attName
if (currentTag.GetAttribute(attribute).Equals(attName))
{
// Then set its attribute "value".
currentTag.SetAttribute("value", value);
currentTag.Focus();
}
}
}