1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C# Web Control

Discussion in 'C, C++, C#' started by critsab, Aug 8, 2013.

  1. critsab

    critsab Newbie

    Joined:
    Mar 22, 2012
    Messages:
    15
    Likes Received:
    6
    Occupation:
    Software Developer
    I am having problem with filling text area and click on the button using my c# code... please give me example if you have I dont care if you are using webbrowser or watin or whatever...

    TEXT AREA:
    Code:
    <textarea class="textarea" placeholder="Say something" style="overflow: hidden;"></textarea>

    BUTTON:
    Code:
    <div class="comment-submit-container">
    <button class="comment-submit" type="submit">Post Comment</button>
    <img class="comment-submit-loading" width="16" height="16" src="ling was here" alt="">
    </div>
    
    
    this is what I have tried so far but it is not working..

    Code:
    webBrowser1.DocumentText = "text with classes";
    webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
    
    void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
    
                foreach (HtmlElement txt in webBrowser1.Document.GetElementsByTagName("textarea"))
                {
                    if (txt.GetAttribute("ClassName") == "textarea")
                    {
                        txt.SetAttribute("value", "adsasdassd");
                       // MessageBox.Show("uneseno");
                    }
                }
           foreach (HtmlElement btn in webBrowser1.Document.GetElementsByTagName("button"))
                {
                    if (btn.GetAttribute("ClassName") == "comment-submit")
                    {
                        btn.InvokeMember("Click");
                        MessageBox.Show("kliknuto");
                    }
                }
    
    
            }
    
    
    
     
    Last edited: Aug 8, 2013
  2. cosmo342

    cosmo342 Newbie

    Joined:
    Aug 16, 2010
    Messages:
    36
    Likes Received:
    2
    Make sure those controls are in Document you search in and not in nested frame

    It is very useful to have FireBug add-on in Firefox. Helps to troubleshoot issues like yours very quick.
     
  3. critsab

    critsab Newbie

    Joined:
    Mar 22, 2012
    Messages:
    15
    Likes Received:
    6
    Occupation:
    Software Developer
    I used it to show you this sc. Can you try to help me with providing c# code maybe?
     
    • Thanks Thanks x 1
  4. rootjazz

    rootjazz Jr. VIP Jr. VIP

    Joined:
    Dec 21, 2012
    Messages:
    614
    Likes Received:
    313
    Occupation:
    Developer
    Location:
    UK
    Home Page:
    Why are you using the webcontrol rather than selenium and one of the many drivers?

    There may be valid reasons, but apart from embedding it in the app, I cannot think of any, and embedding shouldn't really be a decision maker imo.
     
  5. sm754

    sm754 Registered Member

    Joined:
    Mar 21, 2012
    Messages:
    93
    Likes Received:
    38
    Occupation:
    Farmer
    Location:
    Azerbaijan
    If you want real fun, try dealing with the IWebBrowser2 interface.
     
  6. Dolma

    Dolma Registered Member

    Joined:
    Aug 16, 2013
    Messages:
    51
    Likes Received:
    10
    Gender:
    Male
    Occupation:
    http://youronestop.net/
    Location:
    http://youronestop.net/
    Home Page:
    great post