-1

I've got a problem. I want to do the following, as soon as some text is found on WebBrowser1 - do something.

For example we have this HTML:

<div class="chat-message-text">
    
    Somebody just joined us..
    
  </div>

I want when part of this text, for example "joined us" is found on the webbrowser1 some action to be executed..

That's what I've done so far in order to achieve this:

             HtmlElementCollection elc = webBrowser1.Document.GetElementsByTagName("div class");
         HtmlElement el = (from HtmlElement eli in elc
                           where eli.GetAttribute("chat-message-text") == "joined"
                           select eli).FirstOrDefault();

         if (el != null)
         {
             MessageBox.Show("yes");
         }
         else
         {
             MessageBox.Show("no");
         }

and its not working, I have the text visible on webbrowser1 and it displays msgbox saying "no"..

Also second less important question, I made this code on a button.. How I can make it automatic? Like check for this text whether we have it on the webbrowser every 1 second or what? Should I create a loop?

Thank you in advance!

Kaloian
  • 9
  • 1
  • `.GetElementsByTagName("DIV")` -- `if ([HtmlElement].GetAttribute("className") == "chat-message-text") string innerText = [HtmlElement].InnerText;`-- See the notes [here](https://stackoverflow.com/a/53218064/7444103) when parsing a HtmlDocument. – Jimi Mar 07 '20 at 22:17

1 Answers1

0

You should only give "div" to GetElementsByTagName:

HtmlElementCollection elc = webBrowser1.Document.GetElementsByTagName("div");
Anis R.
  • 6,656
  • 2
  • 15
  • 37
  • I just tried that as well, it still displays "no". Looking forward for a complete and accurate answer to my question, thanks. – Kaloian Mar 07 '20 at 21:26