How to fill text area and click on button using c#? -


i having problem filling text area , click on button using c# code... please give me example if have dont care if using webbrowser or watin or whatever...

<textarea class="textarea" placeholder="say something" style="overflow: hidden;"></textarea>    <div class="comment-submit-container"> <button class="comment-submit" type="submit">post comment</button> <img class="comment-submit-loading" width="16" height="16" src="www.notimportantlink.com" alt=""> </div> 

this have tried using class..basically stackoverflow

webbrowser1.documenttext = "text 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");                 }             }           } 

as can see in html code there no id or name..

in watin can use find.byclass or index find elements

this flash button, not click it, proof of concept

var ie = new ie(); ie.goto(@"[link goes here"); ie.textfield(find.byclass("textarea")).typetext("words go here"); ie.button(find.byclass("comment-submit")).flash(2); 

if class textarea not unique, can return elements of type , refernce index. eg: ie.textfields[0].typetext("words go here index");

or combine find criteria ie.textfield(find.byclass("textarea") && find.byindex(0)).typetext("words go here compound find");

.

html used

<html> <title>this title.</title> <body> <textarea class="textarea" placeholder="say something" style="overflow: hidden;"></textarea> <div class="comment-submit-container"> <button class="comment-submit" type="submit">post comment</button> <img class="comment-submit-loading" width="16" height="16" src="www.notimportantlink.com" alt=""> </div> </body> <html> 

tested on watin 2.1, ie9, win7 64bit


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -