Skybound Gecko。如何按类名单击项目?

时间:2014-12-08 18:25:31

标签: c# gecko geckofx

此项目如下所示:

//First "button"
<td ref="somethink_ref1" class="class_name">
        <b>Text_1</b><br>
        text<span class="class_name_1">text</span><br>
        <span class="class_name_2">text</span><br>
        <span class="class_name_3">text</span>text
</td>
//Second "button"
<td ref="somethink_ref2" class="class_name">
        <b>Text_1</b><br>
        text<span class="class_name_1">text</span><br>
        <span class="class_name_2">text</span><br>
        <span class="class_name_3">text</span>text
</td>

没有任何ID,当我使用它时:

        GeckoElementCollection tagsCollection = geckoWebBrowser1.Document.GetElementsByTagName("td");

        foreach (GeckoElement currentTag in tagsCollection)
        {
            if (currentTag.GetAttribute("class").Equals("class_name"))
            {
                 //currentTag.CLICK THIS!;
            }
            //delay some seconds to click next button...
        }

我无意更换“currentTag.CLICK”这个&#39;真正点击通话......

1 个答案:

答案 0 :(得分:3)

如果您使用相对新版本的geckofx,那么您可以执行以下操作:

foreach (GeckoElement currentTag in tagsCollection)
        {
            if (currentTag.GetAttribute("class").Equals("class_name"))
            {
                 ((GeckoHtmlElement)currentTag).Click()
            }
            //delay some seconds to click next button...
        }

虽然我可能会这样做:

var elements = geckoWebBrowser1.Document.GetElementsByClassName("class_name").Where(x is GeckoHtmlElement)

找到节点。