This is a migrated thread and some comments may be shown as answers.

help with scripting

3 Answers 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Divya
Top achievements
Rank 1
Divya asked on 09 Feb 2012, 04:17 PM
Hi

I am trying to write a vb script to generate a random text to be inserted into text box. how do I extract the random text from script to the textbox? any help is appreciated.

Thanks

3 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 09 Feb 2012, 05:12 PM
Hi Divya,

Please see this article from our Code Samples section on "Generate Random Text" and let me know if you need further assistance on this.

Kind regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Divya
Top achievements
Rank 1
answered on 10 Feb 2012, 03:53 AM
Hi Plamen,

Thanks for the reply but I have another question related to the same. I am trying to generate a random text and put it into a textbox which is part of a table and this table has no id or title. So how do I proceed with "Find.ById" if I do have id for the textbox but not the table? (textbox is one of the fields in the table). after running the code below it displays null and stops.
ActiveBrowser.NavigateTo("https://secure.abcsoftware.com/index.asp");
              
            // Wait for '1000' msec.
            System.Threading.Thread.Sleep(5000);
             
            // Enter text 'aaaa' in 'TxtUsernameText'
            Pages.abcSoftwareLogin0.TxtUsernameText.Text = "aaaa";
             
              // Wait for '1000' msec.
            System.Threading.Thread.Sleep(1000);
             
            // Enter text 'bbbb1' in 'TxtPasswordPassword'
            Pages.abcSoftwareLogin0.TxtPasswordPassword.Text = "bbbbbb1";
             
              // Wait for '1000' msec.
            System.Threading.Thread.Sleep(5000);
             
            // Click 'LbtnSubmitLoginLink'
            Pages.abcSoftwareLogin0.LbtnSubmitLoginLink.Click(false);
             
              // Wait for '1000' msec.
            System.Threading.Thread.Sleep(5000);
             
            // Click 'CtrlEntListRptSitesLinkSitesInfo0Link'
            Pages.abcSoftwareLogin0.CtrlEntListRptSitesLinkSitesInfo0Link.Click(false);
             
              // Wait for '1000' msec.
            System.Threading.Thread.Sleep(5000);
             
            // Click 'Nav8Link'
            Pages.abcSoftwareCOM.FrameNavigation.Nav8Link.Click(false);
             
              // Wait for '1000' msec.
            System.Threading.Thread.Sleep(5000);
             
            // Click 'AddNewLink'
            Pages.abcSoftwareCOM.FrameNavigation.AddNewLink.Click(false);
             
            // Wait for '1000' msec.
            System.Threading.Thread.Sleep(5000);
             
            //Define the length of the text
int length = 8;
//Define the included characters
string charSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
Random random = new Random();
string randomText = new String(Enumerable.Repeat(charSet, length).Select(set => set[random.Next(set.Length)]).ToArray());
 
var obj = Find.ById<HtmlContainerControl>("frmAddClient");
if (obj == null)
    Console.Out.WriteLine("Null");
else
    Console.Out.WriteLine(obj.ChildNodes.Count());
Console.In.ReadLine();

Thanks.
0
Plamen
Telerik team
answered on 13 Feb 2012, 06:21 PM
Hello Divya,

I saw you are using the Pages class to locate the elements on the previous steps. You can do the same with the textblock where you want to enter the random text. Please check this video.

You can also use the Find method to locate the textbox, but it's hard to say how to do that without seeing the DOM. One thing you can do is to check how Test Studio is searching for the element (see this article) and then you can use the same Find Logic in code using the identification methods.  

Kind regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Divya
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Divya
Top achievements
Rank 1
Share this question
or