簡體   English   中英

如何通過 href 查找和單擊鏈接/按鈕? (GeckoFx 瀏覽器)

[英]How to find and click links/buttons by href? (GeckoFx browser)

過去我使用

       GeckoElementCollection elements = iframe.ContentDocument.GetElementsByName("name");
            foreach (var element in elements)
            {

                 if (element.GetAttribute("href") == "text")
                 {
                     MessageBox.Show(element.GetAttribute("class"));
                 }
              }

所以我按名稱查找元素,然后我檢查了 href 是否我試圖找到它的元素。 現在我沒有任何元素名稱只有類(類對於少數元素是相同的),唯一的是href。 所以我需要通過 href 搜索元素並用它執行點擊/輸入事件。

我相信我需要使用 GeckoNode

    GeckoNode node = iframe.ContentDocument.GetElementsByClassName("classname")[0].FirstChild;
             if (NodeType.Element == node.NodeType)
             {
                 MessageBox.Show(node.GetAttribute("hreff"));

             }

但是 GetAttribute 不適用於節點。有什么想法嗎?

我知道這個問題很老,但今天我遇到了同樣的問題,我解決了它。 嘗試這樣的事情:

GeckoElementCollection fblikes = webBrowser.Document.GetElementsByTagName("a");
            foreach (GeckoHtmlElement item in fblikes)
            {
                string aux = item.GetAttribute("href");
                if (!string.IsNullOrWhiteSpace(aux) && aux.Equals("p.php?p=facebook"))
                {
                    item.Click();

                }
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM