Element Characteristic Search

3 posts, 0 answers
  1. Paul
    Paul avatar
    4 posts
    Member since:
    Dec 2010

    Posted 18 Jan 2011 Link to this post

    Due to something that our developers do around here that I do not fully understand, there are times within the web page that our element IDs prefix will change from one build to the next.  What I am trying to do is be able to scan through the elements within the page and find one that matches a pattern to then define a test ID prefix to then be used throughout the rest of the test for locating and manipulating the test.  The method I am attempting is basically:

    For each Element in Active Browser
         If Element ID contains Mask1
               Prefix = Constant1
         If Element ID contains Mask2
               Prefix = Constant2

    But when I enter the code I am shown an error that the Browser does not contain a GetEnumerator definition.  I am code savvy enough to be mildly annoying but only self taught so not smart enough to know if there is something that I am supposed to use instead.  Does anybody have any suggestions?

    Thank you.
  2. Paul
    Paul avatar
    4 posts
    Member since:
    Dec 2010

    Posted 18 Jan 2011 Link to this post

    I have found that within tests I can code to use the Find.By... feature, but I am building functions that are called by multiple tests where I cannot access this ability.  Is there some property/setting/special way to hold my tongue so that I can use the Find feature within a function outside of the test area that will allow me this same access?
  3. Stoich
    Stoich avatar
    1 posts

    Posted 21 Jan 2011 Link to this post

    Hi Paul,
       thank you for choosing to evaluate WebUI Test Studio!

    I think I understand what you're trying to do.
    However, don't focus your efforts on trying to determine what the Prefix is. Each HTML element you use in your test is added to the test project along with the Logic needed to find it. The Find Logic is generated during the recording of your test. So basically you recorder some elements with the Find Logic "id=prefix1:something" and now you need to change that Find Logic to "id=prefix2:something". This won't work - even if you determine the Prefix you'll have a hard time writing the code that edits each element's Find logic. I'm not even sure it can be done at all.
    Instead you want to ignore either the prefix or the ID altogether.

    OK, there are a couple of ways to get this to work:
      1) Configure WebUI not to locate Elements based on ID. - this is easier but you'll need to re-record your tests in order to generate new, id-free Find Logic for your elements. Keep in mind that ID is probably the most reliable way to find an Element. By not using it you're sacrificing reliability.
    Open UserSettings, go to "Identification Logic" and delete "Id" from the list (see screenshot 1).

     2) Edit the Find Logic for each element to ignore the prefix. - basically you're going to edit the Find Logic for each affected element. Instead of (ID exact "prefix:something") we want to change it to (ID contains "something") and just ignore the prefix. Open a WebAii Test in Visual Studio. You should be able to find the Elements Explorer that displays all the elements used in the test. To edit the Logic right-click on a element and choose "Edit Element" (screenshot 2) The Find Expression Builder appears. Here's you'll see the expression "id exact something". Change it to "contains" and remove the prefix from the string (see screenshot 3). Do this for each element uses ID in each test.

    I hope I've managed to give you a good answer, please let me know if you need more help with this!

    the Telerik team
    Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Back to Top