SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Apr 2004
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Dynamically Named Objects

    The names of the objects in the app I am working on are generated dynamically with an _# attached at the end of the object name. The names are different for every piece of data and since they continue to move the position of objects on the screen, I cannot rely on relative positioning.

    Names look like this:

    ("http://someURL.com").INPUT.SWUser_firstName_12
    ("http://someURL.com").INPUT.SWUser_firstName_85
    ("http://someURL.com").INPUT.SWUser_firstName_15

    There can be more than one SWUser_firstname on a page, each has a different number.

    I tried using the wildcards in place odf the _# and got syntax errors in my code. I am not a programmer and have no idea what else to try.

  2. #2
    Member
    Join Date
    Oct 2002
    Location
    Kansas City
    Posts
    79
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Dynamically Named Objects

    If you are using VBScript you can use the Execute statement. Build your statemet like below:

    dynamicVar = 12
    var = "(" & Chr(34) & "http://someURL.com" & Chr(34) & ").INPUT.SWUser_firstName_" & dynamicVar & ".SetFocus"
    Execute var

    The part you will need to develop on your side is the logic for setting the dynamicVar value. If there is no consistent AUT logic or if you are not running data driven test scenarios you may need to develop an enumeration of the Parent.ChildList and address each instance of the target control type.

    You can even Execute an entire Sub if you need:

    S = "Sub ExecutePrint" & vbCrLf
    S = S & " Print X" & vbCrLf
    S = S & "End Sub"
    Execute S

    [ 05-18-2004, 10:40 AM: Message edited by: kadams ]

  3. #3
    Junior Member
    Join Date
    Aug 2004
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Dynamically Named Objects

    This is very nice but what if you want to do some validation before performing an operation? For example:

    page.INPUT.someItem_1.Click 'does object exist and support a click operation?
    page.INPUT.someItem_2.Click

    How would one write a routine that does the following for any INPUT field specified by name?:

    Set Obj = page.INPUT.someItem_1
    If IsSupported(Obj, "Exists") Then
    If IsSupported(Obj, "Click") Then
    Obj.Click
    End If
    End If

    Or maybe I should ask the question differently: Is there a way to find an object from a dynamically build string (Variant)?
    Var = page.INPUT. & specifiedName
    Set Obj = VarToObject(Var) '???

    Or do I have to switch from VBScript to C++Script?

  4. #4
    Senior Member
    Join Date
    May 2002
    Location
    Las Vegas, NV, USA
    Posts
    499
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Dynamically Named Objects

    Hi,

    Yes, you can use the WaitChild method to get an object of a web page using the name mask and see if it supports the given method. The script below demonstrates this approach. It works with the current page.
    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">[VBScript]

    Set p = Sys.Process(&quot;IEXPLORE&quot
    Set w = p.Window(&quot;IEFrame&quot;, &quot;*&quot
    w.Activate
    Set window = w.Page(&quot;*&quot
    NameMask = &quot;submit_*&quot;
    MethodName = &quot;Click&quot;
    Set ChildObj = window.INPUT.WaitChild(NameMask)
    If ChildObj.Exists Then
    If IsSupported(ChildObj, MethodName) Then
    Log.Message(&quot;The object &quot; &amp; ChildObj.Name &amp; &quot; supports the method &quot; &amp; MethodName &amp; &quot;.&quot
    End If
    End If</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">
    Regards,
    Bobby Edgar
    Olagoo.com
    Save on AutomatedQA Products

  5. #5
    Junior Member
    Join Date
    Aug 2004
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Dynamically Named Objects

    Thank you Bobby.

    Since my previous post I've swapped over to C++Script which allow the following:

    [C++Script]
    function Click(IEpage, frame, tagName, name)
    {
    var Obj;

    Obj = IEpage[frame][tagName][name];
    if (IsSupported(Obj, "Exists"))
    {
    if (Obj["Exists"])
    if (IsSupported(Obj, "Click"))
    Obj["Click"]();
    }
    }

    Click(window, "TargetContent", "A", "Payment");
    Click(window, "TargetContent", "INPUT", "Amount");


    Which in VB would require multiple lines of code:
    [VBScript]
    Set ChildObj = window.WaitChild("TargetContent")
    Set ChildObj = ChildObj.WaitChild("A")
    Set ChildObj = ChildObj.WaitChild(Payment)
    If ChildObj.Exists Then
    If IsSupported(ChildObj, "Click") Then
    ChildObj.Click
    End If
    End If


    For the benefit of other readers please note that the Tree model must be set to "Tag".

    Johan Wolmarans

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.00%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 02:17 PM.

Copyright BetaSoft Inc.