views:

229

answers:

4

Hi,

For learning purposes I would like to automate some parts in a browser game, currently I am trying to fill out some simple text boxes, without any luck though. I've created a WebBrowser component on my form, loaded the website via it and tried this.

webBrowser1.Document.GetElementById("citizen_name").SetAttribute("", "myname");

When I click my "fill out text box" button nothing happens. The HTML part looks like this:

<input type="text" name="citizen_name" id="citizen_name" value="" class="field" tabindex="1" />

I am talking about the eRepublik.com game, appreciate any help.

+5  A: 

Try this:

HtmlDocument document = this.webBrowser1.Document;
document.GetElementById("citizen_name").SetAttribute("value", "myname");
Nate Shoffner
A: 

For this kind of problems there are much more suitable environments.

The easiest to use is definitely userscripts.

What exactly do you want to learn? How to test web apps, or how to develop them?

glebm
A: 

You can use of course simple javascript that you include in your page, or better yet, using Greasemonkey , so you don't modify the "client" code.

But greasemonkey would only be an option for Firefox, Opera and Chrome. If you really need a full blown cross browser automation test suite, you could use Sellenium IDE, that allows to record or script a series of interactions with a web page, that can be automatically run in any of its supported browsers.

voyager
+1  A: 

I usually take the following approach:

var someElem = webBrowser1.Document.GetElementById("some_id");
if (someElem != null)
{
   someElem.InnerText = "Some value";
}

Some textareas of advanced editors cannot have their value set this way. To handle them I do something like the following:

someElem.Focus();
Windows.Forms.SendKeys.SendWait("Some value");
abscode