简体   繁体   中英

Get elements from child class

So, i am creating a project using C# and Gecko(firefox) browser. One of the things that i want to do, is to read the text(actually it's a number) of a span class from the html "code" of an website.

Here is the part of the html element i am interested of: http://prntscr.com/e8sne4

I used this piece of code to read the number:

var links = GeckoWB.Document.GetElementsByClassName("ipsNotificationCount");

        foreach (GeckoHtmlElement link in links)
        {
            string value = link.GetAttribute("data-currentcount");
            if (!string.IsNullOrWhiteSpace(value))
            {
                MsgLbl.Text = value;
                break;
            }
        }

This piece of code works like a charm... but there is one main problem. There are more than one "sub-classes" inside the html code of the webpage with the name "ipsNotificationCount" that contain an html element named "data-currentcount".. At least two. How in the world i am suppose to take the take ONLY the"data-currentcount" element from the "ipsNotificationCount" sub-class of the "fa fa-envelope" class ?? I searched all the available methods and i cannot find anything. Neither on google. Any suggestion ?

I managed to solve this problem just by finding at what order every class "instance" of the "ipsNotificationCount" sub-class is and gather the info. It's not a pro way, but works.

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