- This topic has 1 reply, 2 voices, and was last updated 8 years, 7 months ago by EveryStep Support.
-
AuthorPosts
-
April 18, 2016 at 11:36 am #2422RyanGuest
Is there a way to have the automation input a random number between a predefined range? Say where age is the constraint (min age of 18 max age of 120). Likewise entering a date range?
Also, while at it, is there a way to allow random selections (or alternating even) for say radio buttons (use male / female gender radio buttons as example)
April 19, 2016 at 10:30 am #2432EveryStep SupportModeratorYes, you can enter valid C# code that will randomize values to enter into fields.
Here are the two examples you requested:Entering age between 18 and 120 y.o.
// script_version=3.0; everystep_version=4.0.5953.25078; date=4/19/2016; IE=11.0.9600.17126
Tabs.ConfigureIEVersion (BrowserMode.IE11, DocumentMode.IE11Emulate);
Tabs.SetSize (1768, 651);
DMBrowser tab0 = null;
Step (1, “The input element – HTML5 tutorial – http://www.html-5-tutorial.com/input-element.php”);
tab0 = Tabs.NewTab ();
tab0.GoTo (“http://www.html-5-tutorial.com/input-element.php”);
// produces random number in range from 18 to 120
int r = (new Random(DateTime.Now.Second)).Next(18, 121);
tab0.TextField (“//INPUT[@TYPE=\”number\”]”, “//INPUT[@NAME=\”age\”]”, “//B[normalize-space()=\”Age:\”]/..//INPUT”).TypeText (r.ToString());Choosing randomly male or female gender
// script_version=3.0; everystep_version=4.0.5953.25078; date=4/19/2016; IE=11.0.9600.17126
Tabs.ConfigureIEVersion (BrowserMode.IE11, DocumentMode.IE11Emulate);
Tabs.SetSize (1768, 714);
DMBrowser tab0 = null;
Step (1, “visible – http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio”);
tab0 = Tabs.NewTab ();
tab0.GoTo (“http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio”);for (int i = 0; i < 5; i++)
{
// produces random number in range from 0 to 2
int r = (new Random(DateTime.Now.Second)).Next(0, 3);if (r == 0)
{
tab0.Frame (“//IFRAME[@ID=\”iframeResult\”]”, “//IFRAME”).RadioButton (“//INPUT[@VALUE=\”female\”]”, “//INPUT[@VALUE=\”other\”]/preceding-sibling::INPUT[1]”, “//INPUT[@VALUE=\”male\”]/following-sibling::INPUT[1]”).Click ();
}
else if (r == 1)
{
tab0.Frame (“//IFRAME[@ID=\”iframeResult\”]”, “//IFRAME”).RadioButton (“//INPUT[@VALUE=\”other\”]”, “//INPUT[@VALUE=\”female\”]/following-sibling::INPUT[1]”, “//INPUT[@VALUE=\”male\”]/following-sibling::INPUT[2]”).Click ();
}
else if (r == 2)
{
tab0.Frame (“//IFRAME[@ID=\”iframeResult\”]”, “//IFRAME”).RadioButton (“//INPUT[@VALUE=\”male\”]”, “(//INPUT[@TYPE=\”radio\”])[1]”, “(//INPUT[@NAME=\”gender\”])[1]”).Click ();
}Delay(“3sec”.ToDuration());
} -
AuthorPosts
- You must be logged in to reply to this topic.