0

我是 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");

错误是:

无法隐式转换类型“Skybound.Gecko.GeckoElementCollection”
    到“System.Windows.Forms.HtmlElementCollection”

任何想法如何解决这个问题?

4

1 回答 1

3

GetElementsByTagNameon 方法GeckoDocument不返回 a HtmlElementCollection,它返回 a GeckoElementCollection(它又包含s,而GeckoElement不是HtmlElements)。

所以你需要这样的东西(未经测试):

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();
        }
    }
}
于 2013-07-03T19:31:48.897 回答