简体   繁体   中英

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

In the past I were using

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

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

So I were finding element by name and then I checked href if its element which im trying to find. Now I dont have any element name only class (class is same for few elements) and what is unique is href. So I need to search element by href and perform click/input events with it.

I believe that I need to use GeckoNode

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

             }

However GetAttribute dont work with nodes.. Any ideas?

I know the question is old, but today I had same problem and I fix it. Try something like this :

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();

                }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM