2014-09-23 43 views
0

在過去,我用如何通過href找到並點擊鏈接/按鈕? (GeckoFx瀏覽器)

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

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

所以我找到了由name元素,然後我檢查HREF如果元素,其即時通訊試圖找到。 現在我沒有任何元素名稱只有類(類是少數元素相同),什麼是獨特的是href。所以我需要通過href搜索元素,並使用它執行點擊/輸入事件。

我相信,我需要使用GeckoNode

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

      } 

不過的getAttribute不與節點工作..任何想法?

回答

1

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

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

       } 
      } 
相關問題