Thursday, 13 August 2009

My Answer(s) posted on Code Project web site Part-1

In this Blog i would like to share my Answers which i have posted on Code project.
Question: Can WatiN accept inputs from an Excel sheet
Can WatiN accept inputs form an excel sheet. this functionality was there in watir.
Is this available in WatiN.

Jawed: yes it is.for that you need to write simple C# code to read from excel sheet.see below
some example from my side.

public class CommonClassAutomation
static string connectionString
= "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=
D:/test.xls;Extended Properties=Excel 8.0;";
public static string inputText= string.Empty;

public void TC_googletest()

//before calling instance of browser read input from excel sheet.
//Open instance of IE browser.
IE ie=new IE();
//Open in browser
/*Provide input text in to google search box. which you have already having from
excel sheet.*/
//Click on Search button.
//Method To read data from Excel sheet
public void readExcelsheet()
DbProviderFactory factory = DbProviderFactories.GetFactory
int inputCount=0;
using (DbConnection connection = factory.CreateConnection())
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
command.CommandText = "SELECT * FROM ["+ sheetName+"$]";
using (DbDataReader dr = command.ExecuteReader())
if (dr.Read())
inputText= dr[1].ToString();
catch(Exception ex)
//To Do
Hope, it would be useful for you.
happy automation
Hi I'm working on WatiN tool. I've scenario where i need to check a checkbox and click on ok button in the popup window. i've used AttachtoIE method and used URL attribute to attach to the popup window. Now the problem is URL contains the ID value, which changes each time the popup appears.. so how to handle this or is there any other method other than AttachtoIE.
please give some suggestion thanking you.
Other Member: Yes I got it right, I ignored the query string part in the URL which used to change everytime.
for example, the above URL the second line is the query string which will be present after the question mark in the first I used only the first line neglecting the second like this
IE popup = IE.AttachToIE(Find.ByUrl(Url, true);
this worked for me, hope this will help you
Jawed: Hi,@ninay_fz: nice reply
Just I want to add few points over here to make your piece of code to work with dynamic changing URL.In this situation is good practice to use Regular expression.
Add this name space to your code file.

using System.Text.RegularExpressions;

Use below code to generalize while accessing URL.
string Url= "";(or whatever string you want to put!!)
Regex reg = new Regex(Url);
IE popup = IE.AttachToIE(Find.ByUrl(reg , true));
Hope it would solve your problem.