Select HTML List

4 posts, 0 answers
  1. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 18 Oct 2011 Link to this post

    I have the following code to select an item based on the user role I need to create.  Is there a simpler way to do this?

    Thanks,

    John

    'Default Span
    ActiveBrowser.Window.SetFocus
    Pages.CreateNewUser.PleaseSelectSpan.ScrollToVisible(ArtOfTest.WebAii.Core.ScrollToVisibleType.ElementTopAtWindowTop)
    Pages.CreateNewUser.PleaseSelectSpan.MouseClick
     
     
    If  Data("firstname")  =  "admin"  Then
            'Click 'ProgramListItem'
        ActiveBrowser.Window.SetFocus
        Pages.CreateNewUser.ProgramListItem.ScrollToVisible(ArtOfTest.WebAii.Core.ScrollToVisibleType.ElementTopAtWindowTop)
        Pages.CreateNewUser.ProgramListItem.MouseClick
    End   If
     
    If  Data("firstname")  =  "man"  Then
        'Click 'SiteManagerListItem'
        ActiveBrowser.Window.SetFocus
        Pages.CreateNewUser.SiteManagerListItem.ScrollToVisible(ArtOfTest.WebAii.Core.ScrollToVisibleType.ElementTopAtWindowTop)
        Pages.CreateNewUser.SiteManagerListItem.MouseClick
    End  If
     
    If  Data("firstname")  =  "staff"  Then
        'Click 'StaffMemberListItem'
        ActiveBrowser.Window.SetFocus
        Pages.CreateNewUser.StaffMemberListItem.ScrollToVisible(ArtOfTest.WebAii.Core.ScrollToVisibleType.ElementTopAtWindowTop)
        Pages.CreateNewUser.StaffMemberListItem.MouseClick
    End  If
     
    <option value="">Please select</option>
    <option value="1">Program administrator</option>
    <option value="2">Site manager</option>
    <option value="4">Staff member</option>

  2. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 19 Oct 2011 Link to this post

    Hello John,
         judging by the HTML for the control it's an HTML select.
    Let's say it's stored in the Repository (i.e. Elements Explorer) under the following name:
    Pages.CreateNewUser.[Select]
    This means you'll be able to make a selection with the following piece of code:
    Pages.CreateNewUser.[Select].SelectByText("userName", True)

    Now you need to change the entries in the "firstname" column in your datasource. They need to resemble the exact text from the <option> elements:
    Program administrator
    Site manager
    Staff member


    Now you can make the selection with a single line of code:
    Pages.CreateNewUser.[Select].SelectByText(DirectCast(Data("firstname"), [String]), [True])

    All the best,
    Stoich
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 19 Oct 2011 Link to this post

    Stoich,
    I get the following error now.

    C:\Users\Public\Documents\Auto\QA\Telerik\EDTestProject\Edition 4.0\Create User\Create New User WebTest.tstest.vb: Line 74: (BC30456) 'Select' is not a member of 'Pages.CreateNewUserPage'.
    C:\Users\Public\Documents\Auto\QA\Telerik\EDTestProject\Edition 4.0\Create User\Create New User WebTest.tstest.vb: Line 74: (BC30451) 'True' is not declared. It may be inaccessible due to its protection level.


    any thoughts?
    thanks,
    John
  4. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 21 Oct 2011 Link to this post

    Hi John,
       Pages.CreateNewUser.[Select] was just an example which I used in order to demonstrate the basic principle behind this. Depending on your application the control which you're accessing and how it's stored in the Elements Repository will be different.

    First you have to add the control to Elements Explorer:
    http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/elements-pane-overview.aspx
    You can do this by using the Add To Project Elements feature:
    http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/elements-menu.aspx

    Once you've done this you will be able to access the element in code. You will need to determine the exact path to access it. For instance let's say the page which contains the elements has a Title of "My First Page". Let's say the element has a Name attribute of "My Selection Box".
    The statement you will use in order to access this element in code would be something like this:
    Pages.MyFirstPage.MySelectionBox.

    I hope I've managed to explain this concept in a clear manner. Let me know if you require additional assistance with this.

    If your app is publicly available please give me an URL along with a description of the use case you want to implement and I will be happy to create a sample test for you.

    Greetings,
    Stoich
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top