Selenium
Help for Handling Advanced Scripts
Pause Command:
Thread.Sleep(60000);
(60000 is the time to wait for in
milliseconds.)
=============================
Popup Handling:
selenium.WindowFocus();
selenium.WaitForFrameToLoad("aspForm",
"10000");
//place this code in place of code:
selenium.SelectFrame("sb-player");
===================================
Order id Store and Use Command:
string ProPrice = "";
string PID = "";
string OrderID = "";
OrderID =
selenium.GetEval("this.browserbot.getUserWindow().ya_tid");
PID =
selenium.GetEval("this.browserbot.getUserWindow().ya_pid");
ProPrice=selenium.GetEval("this.browserbot.getCurrentWindow().ya_dv");
Assert.IsTrue(selenium.IsTextPresent(OrderID));
=========================================
To open Advanced script in IE:
replace "*chrome" by
"*iexplore" in
selenium = new
DefaultSelenium("localhost", 4444, "*chrome",
"http://ecp.fd2009.dev.fdwork.com/");
To maximize browser
automatically:
selenium.Open("/");
selenium.WindowMaximize();
=================================
Random No. generation code:
Random ra = new Random();
int iRandom = ra.Next();
string sScheduleName = "test"
+ iRandom;
in place of parameter name , use
"sScheduleName"
i.e.
selenium.Type("ctl00_ContentPlaceHolderBody_txtScheduleName",
"test");
will be changed to
selenium.Type("ctl00_ContentPlaceHolderBody_txtScheduleName",
sScheduleName);
e.g-2:
selenium.Click("link=test");
will be changed to
selenium.Click("link=" +
sScheduleName);
e.g-3:
selenium.Type("ctl00_ContentPlaceHolderBody_txtAddListName",
"rough");
will be changed to
string sNewList = "New_List"
+ iRandom;
selenium.Type("ctl00_ContentPlaceHolderBody_txtAddListName",
sNewList);
e.g-4
selenium.Type("ctl00_ContentPlaceHolderBody_txtNewList",
"shweta");
will be changed to
string sMergeList = "Merge_List"
+ iRandom;
selenium.Type("ctl00_ContentPlaceHolderBody_txtNewList",
sMergeList);
Executing a block of code for n
no of times:
int i;
for (i = 1; i < 3; i++)
{
//selenium.Click("//table[@id='ctl00_ContentPlaceHolderBody_gvWebsite']/tbody/tr[17]/td[11]/a");
selenium.Click("//table[@id='ctl00_ContentPlaceHolderBody_gvWebsite']/tbody/tr['"
+ i + "'+1]/td[11]/a");
// the value of 17 is changed to ('" + i + "'+1), Note
the use of single quotes, double quotes and +1.
}
===============================================================
Executing a block of code if a
condition is satisfied and exit the loop if condition is false:
{
if
(!Convert.ToBoolean(selenium.IsTextPresent("Preview")))
//if the condition will true then it will exit the loop, else will
continue the rest code in the loop
{
continue;
}
//rest code
-----
-----
}
===============================================================
No comments:
Post a Comment