0

I'm trying to get the text inside a span in a web browser, the problem is that the span does not have a id.

This is the code I've tried:

        var findhuv1 = webBrowser2.Document.GetElementsByTagName("span").OfType<HtmlElement>()
                        .Where(html => html.GetAttribute("class").Equals("huv1")).FirstOrDefault().InnerText;
        label14.Text = findhuv1;

This is the HTML code on the webpage:

<span class="huv1">6436347</span>

The problem is that my code only returns with an error:

    System.NullReferenceException
System.Linq.Enumerable.FirstOrDefault<TSource>(...) returned null.

I need help to figure out what I'm doing wrong. I don't have access to edit the HTML codes on the webpage.

halfer
  • 19,824
  • 17
  • 99
  • 186
Patric Nøis
  • 208
  • 2
  • 8
  • 27
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Trevor Mar 04 '20 at 20:30
  • @Çöđěxěŕ Couldnt figure out the right way to get the text whit that – Patric Nøis Mar 04 '20 at 22:45

0 Answers0