C# Web Control

critsab

Newbie
Joined
Mar 22, 2012
Messages
15
Reaction score
6
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:
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.
 
I used it to show you this sc. Can you try to help me with providing c# code maybe?
 
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.
 
If you want real fun, try dealing with the IWebBrowser2 interface.
 
Back
Top