views:

786

answers:

5

i wish to interact with my browser window may be IE great if it works on Firefox too, using C#.

I want to make a software which can fill the entries in a webform automatically. In old times there was gator now is roboform, where it can fill in the values automatically.

I actually have users who are comfortable working on an old windows forms application, so i want to make a solution where they can still enter the data in their windows application and it actually fills in the entries at the web form and acts as if the request had generated from the browser itself.

I know i can merge both the databases, since it is a legacy application re writing the database for windows app is a trouble..

Any suggestion?

A: 

If you use fiddler you may be able to see what the browser sends back to the server, and so you could write C# code to generate the same kind of HTTP request.

If the interaction is very complex (it often is with modern webapps), you could instead automate the browser, as you suggested.

I've had some success automating IE by using the InternetExplorer.Application object. It basically launches a copy of IE and lets you control it from code. I wrote a script this way a few years ago to search for cheap train ticket reservations for me on the Virgin Trains website.

The problem was that with some IE installs, it would sometimes stop to give security warnings that I couldn't skip automatically. There didn't seem to be a pattern to this.

Daniel Earwicker
+4  A: 

WatiN is designed to make testing web applications easy from .NET, and it sounds like it could be handy for what you want to do:

Following is the Hello world example of web test automation; searching Google.

[Test] public void
SearchForWatiNOnGoogle() {  using (IE
ie = new IE("http://www.google.com")) 
{  
ie.TextField(Find.ByName("q")).TypeText("WatiN");
ie.Button(Find.ByName("btnG")).Click();
     Assert.IsTrue(ie.ContainsText("WatiN"));
} }

WatiN Feature List

  • Automates all major HTML elements
  • Find elements by multiple attributes
  • Supports AJAX website testing
  • Supports frames (cross domain) and iframes
  • Supports popup dialogs like alert, confirm, login etc..
  • Supports HTML dialogs (modal and modeless)
  • Works with Internet Explorer 6, 7, 8 and FireFox 2 and 3
AakashM
+2  A: 

It's billed as a testing application, but Selenium RC can be used to fill in forms and is fairly easy to setup. You could also check out WatiN. Don't know anything about what security issues you might see though.

s_hewitt
A: 

If your users are simply using the application via a WindForms application, then is there any particular reason why you have to manipulate the user interface of an existing web browser, such as Internet Explorer, rather than just making the necessary HTTP requests yourself in your WinForms application? You can use the WebRequest class by setting the Method property to "POST" and writing the field data to the Stream, which you can get using the httpRequest.GetRequestStream() method.

IRBMe
A: 

You might also want to check out Selenium which is a web application testing framework that you can programmitically interact the web UI.

jamesaharvey