help with scripting

4 posts, 0 answers
  1. Divya
    Divya avatar
    3 posts
    Member since:
    Jan 2012

    Posted 09 Feb 2012 Link to this post

    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
  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 09 Feb 2012 Link to this post

    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
  3. Divya
    Divya avatar
    3 posts
    Member since:
    Jan 2012

    Posted 09 Feb 2012 Link to this post

    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.
  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 13 Feb 2012 Link to this post

    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
Back to Top