How to find a number inside an HTML list

Asked

Viewed 107 times

0

I’m trying to find the number that the person wrote in the box, in Document.getElementByID on the site, but I can’t do in c#, or tried at least:

private void btnvalidar_Click(object sender, EventArgs e)
        {
            if (webrequestNumero.Document.GetElementById("Numero").InnerText.IndexOf(txtNumero.Text) == -1)
            {
                MessageBox.Show("O número está na lista");
            }
            else
            {
                MessageBox.Show("O número não está na lista");
            }
        }

Could someone explain what’s wrong with the code?

  • 2

    Should change to != -1 instead of == 1

  • 1

    Just complementing what @dvd mentioned, see how the IndexOf: https://msdn.microsoft.com/pt-br/library/k8b1470s(v=vs.110). aspx

1 answer

0


Please, you would have an example of the page font?

has several ways to identify if the text is on the site or not.

The box is inside a tag, a TD or TR example if you are, do this code below!

foreach (Htmlelement Html in Webbrowser.Document.Body.Getelementsbytagname("tr")) { Messagebox.Show(Html2.Innertext); }

when doing this function C# will show you a msgbox stating the content of the tag, so if you want you can do an If to identify if the value of the box corresponds to what you are looking for.

or better if the box is in an input with the ID or name you can do otherwise

string = Webbrowser.Documentment.Getelementbyid("Boxdoconteudo"). innertext;

As I had said to countless ways you bring the value of the box, in case this example has helped I will be very happy, if you inform me no doubt?

Atte!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.