browse by category or date

Recently we received a request to provide solution on automating Internet Explorer. In the past, I had similar project which utilises .NET’s web browser control. It was horrid and painful experience 😀 Not wanting to repeat the same nightmare, I googled for better tools.

Then I found WatiN (Web Application Testing in .NET). My preliminary trials has been positive. Just check out below code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core;

namespace IEAutomator
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            //Open an URL
            var browser = new IE("http://sodeve.net/wp-admin");

            //Find a textbox by its elementID and set its value
            var txtLogin = browser.TextField("user_login");
            txtLogin.Value = "admin";

            //Find a password textbox by its elementID and set its value
            var txtPassword = browser.TextField("user_pass");
            txtPassword.Value = "testPass";

            //Find the submit button and then click it
            var btnLogin = browser.Button("wp-submit");
            btnLogin.Click();
            
            //Delay to ensure we can see the result in IE
            Console.ReadLine();

            //Close IE
            browser.Close();
        }
    }
}

I hope I can write more about how WatiN helps me to provide the solution required by my Customer.

About Hardono

Hi, I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 9 years.

No Comment

Add Your Comment