0
<a href="/game.php?yo=120252&amp;screen=info_command&amp;id=1602691855&amp;type=own">
<span class="element1">
    Random text 
</span>

I'm using a Windows-Forms-Application with an integrated webbrowser. Is there any way to retrieve this specific HtmlElement?

Sorry I'm very new to this, if there's some information missing please tell me.

Lesic
  • 136
  • 12
  • 1
    Use `HTML Agility Pack`. Will make life much easier – Fᴀʀʜᴀɴ Aɴᴀᴍ Jan 22 '16 at 17:01
  • What specific element? Neither have an ID. If it did you could use `GetElementById`, but since it doesn't you'd have to iterate through all tags of that class until you find what you want [see here](http://stackoverflow.com/questions/8461932/how-to-getelement-by-class). – Equalsk Jan 22 '16 at 17:03
  • This should help: http://stackoverflow.com/questions/2527499/webbrowser-control-get-element-value-and-store-it-into-a-variable – fredw Jan 22 '16 at 17:30
  • @Equalsk "Random text" is a link label in my browser I want to click on and for that I need the HtmlElement. The link you provided doesnt work, using GetAttribute("className") == "element1"... – Lesic Jan 22 '16 at 17:33
  • @fredw Unfortunately I don't have an ID, so this doesn't work either. – Lesic Jan 22 '16 at 17:34

1 Answers1

0
using System.Linq;
...

var element1 = browser.Document.GetElementsByTagName("span")
      .Where(e => e.GetAttribute("class") == "element1")
      .FirstOrDefault();

element1 will be null if it wasn't found

fredw
  • 1,409
  • 12
  • 23