0

I'm trying to get the text inside a span in a webbrowser, 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 return's with an error:

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

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

zaggler
  • 7,254
  • 6
  • 26
  • 47
Patric Nøis
  • 192
  • 2
  • 6
  • 26
  • 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) – zaggler 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