Results 1 to 2 of 2
  1. #1

    Default [Tutorial]C# - Foreach Statements

    I'm going to teach you to input or click something (i.e textbox or button) using Foreach statements.
    Foreach statements are also good for input or clicking something without a id or name.

    This is webBrowser only.

    Ok, if the html source of a textbox is:

    Code:
    <input id="email" class="textbox_email" type="text" value="" name="email">
    ok so our id is email and our name is email.

    We are going to use id for now, you can use name if you want since there the same


    These are attributes of our Html sources.
    We need theses.

    Theres also type, class, and value, but we don't thoses (for now)

    now here is what we are going to do:

    foreach (HtmlElement umad in webBrowser1.Document.All)
    {

    }

    ok so we are saying for each umad (you can say whatever but I like saying umad ) as HtmlElement (the element/attribute source) in the webpage, do this in between the brackets.

    Now we are going to do this:

    Code:
    foreach (HtmlElement umad in webBrowser1.Document.All)
    {
    if (umad.GetAttribute("id") == "email")
    {
    
    }
    
    }
    Ok, sounds fimilar amirite?
    *cough*webBrowser1.Document.GetElementById("email");*cough*

    Ok now we are going to set the value to what ever you or anyone inputs.

    Code:
    foreach (HtmlElement umad in webBrowser1.Document.All)
    {
    if (umad.GetAttribute("id") == "email")
    {
    umad.SetAttribute("value", txtEmail.Text);
    }
    
    }

    Now if you want to click a button.

    Assuming this is the html source

    Code:
    <input id="submit" class="form_buttonl" type="button" value="" name="submit">

    You would just:

    Code:
    foreach (HtmlElement umad in webBrowser1.Document.All)
    {
    if (umad.GetAttribute("id") == "email")
    {
    umad.InvokeMember("click");
    }
    
    }
    sounds fimilar amirite?
    *cough*webBrowser1.Document.GetElementById("submit").Invo keMember("click");*cough*

  2. #2
    Rank: Rookie
    • Join Date: Feb 2013
    • Posts: 1

    Default

    Quote Originally Posted by FearOfTheDark^ View Post
    I'm going to teach you to input or click something (i.e textbox or button) using Foreach statements.
    Foreach statements are also good for input or clicking something without a id or name.

    This is webBrowser only.

    Ok, if the html source of a textbox is:

    Code:
    <input id="email" class="textbox_email" type="text" value="" name="email">
    ok so our id is email and our name is email.

    We are going to use id for now, you can use name if you want since there the same


    These are attributes of our Html sources.
    We need theses.

    Theres also type, class, and value, but we don't thoses (for now)

    now here is what we are going to do:




    ok so we are saying for each umad (you can say whatever but I like saying umad ) as HtmlElement (the element/attribute source) in the webpage, do this in between the brackets.

    Now we are going to do this:

    Code:
    foreach (HtmlElement umad in webBrowser1.Document.All)
    {
    if (umad.GetAttribute("id") == "email")
    {
    
    }
    
    }
    Ok, sounds fimilar amirite?
    *cough*webBrowser1.Document.GetElementById("email");*cough*

    Ok now we are going to set the value to what ever you or anyone inputs.

    Code:
    foreach (HtmlElement umad in webBrowser1.Document.All)
    {
    if (umad.GetAttribute("id") == "email")
    {
    umad.SetAttribute("value", txtEmail.Text);
    }
    
    }

    Now if you want to click a button.

    Assuming this is the html source

    Code:
    <input id="submit" class="form_buttonl" type="button" value="" name="submit">

    You would just:

    Code:
    foreach (HtmlElement umad in webBrowser1.Document.All)
    {
    if (umad.GetAttribute("id") == "email")
    {
    umad.InvokeMember("click");
    }
    
    }
    sounds fimilar amirite?
    *cough*webBrowser1.Document.GetElementById("submit").Invo keMember("click");*cough*
    Check here some more C# statements tutorial

    http://csharp.net-informations.com/s...s_tutorial.htm

    gerab.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •