Forum Discussion

mfoster711's avatar
mfoster711
Regular Contributor
10 years ago

Empty Span Elements

I am having an issue with empty span elements. I know span elements are not mapped unless they have text or a role.



I am curious if anybody has a suggestion on how to handle my situation. Here is what my section looks like:





<div class="blah blah blah">            


<span class="twoLines displayGroup"><label>VIN</label><span class="value">2FMxxxxxxxxxxxxxx</span></span>


<span class="twoLines displayGroup"><label>Exterior Color</label><span class="value"></span></span>


<span class="twoLines displayGroup"><label>Deal Type</label><span class="value">Retail</span></span>


<span class="twoLines displayGroup"><label>Vehicle Category</label><span class="value">Sedan</span></span>


<span class="twoLines displayGroup"><label>Interior Color</label><span class="value"></span></span>


<span class="twoLines displayGroup"><label>Stock Type</label><span class="value">New</span></span>


<span class="twoLines displayGroup"><label>Style</label><span class="value">4dr SEL FWD</span></span>


<span class="twoLines displayGroup"><label>License Plate #</label><span class="value">GYNASD</span></span>


<span class="twoLines displayGroup"><label>Extended Warranty</label><span class="value"></span></span>


<span class="twoLines displayGroup"><label>Mileage</label><span class="value">10,700</span></span>


<span class="twoLines displayGroup"><label>License Plate Exp Date</label><span class="value"></span></span>


</div>




The problem I have is that the value spans may or may not contain a value. For example, "Exterior Color" is an optional value the use may not have entered. Well, if the value is not entered then TestComplete does not map it. This causes all the TextNodes to shift down one. Where Vehicle Category was TextNode 3 it is not TextNode 2.



How can I check the TextNode values if the number of TextNodes that displays varies depending on whether the user entered information or not?



Alternatively, is there some way to "Find" the correct span based on the Label next to it?



Lastly, Is there a logical reason whey TestComplete does not map empty span elements? Or, is this just flaw with TestComplete that SmartBear does not consider worth the time to fix since nobody complains about it?

4 Replies

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    The short answer here is No. You cannot map, nor logically find an object that has no unique properties or object hierarchy. It's not a flaw or bug. There is simply not enough information for TestComplete to recognize it as a unique object. It could guess...but then it would likely be wrong when the user enters different information. Likely why it's "shifting down" in your mapping because it thinks it's the same object.



    I suggest using an image comparison or alternate method to check the page.



    If you're attempting to click on one of these spans you may want to try clicking on the containing parent object and specifying coordinates. In this case you would click <span class="twoLines displayGroup"> span object at X,Y coordinate (location of child span object).



    If nothing else http://support.smartbear.com/viewarticle/55418/ TARGET='_blank'>Text Recognition may work for this.
  • APX's avatar
    APX
    Occasional Contributor

    Ok, so I have another problem with spans: spans on my page have "idStr" but TestComplete does not recognize it.
    a litle code snippet from my site:

    <div class="bla" id="myDiv">
            <span class="mySpan" id="spanOfDiv" onclick="doSomething()">A short Text about a sleeping Cat</span>
    </div>

    I use following function to search for span:

    FindChild("idStr", "spanOfDiv", 10)

     

    Anybody else here with the same problem or does anyone know a solution?

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    The quick idea is to search for the label and then use its sibling (which,according to the layout you've provided should be a span element).

    Something like this (untested pseudocode):

    Set oLabel = <RootObject>.FindChild(Array("ObjectIdentifier", "contentText"), Array("Label", "VIN"), 20)

    If (Not oLabel.Exists) Then

      ...

    Set oSpan = oLabel.Parent.FindChild("ObjectIdentifier", "Span", 0)

    or

    Set oSpan = oLabel.Parent.FindChildByXPath("./SPAN")

    if for some reason .FindChild does not work.

     

    • APX's avatar
      APX
      Occasional Contributor

      Thanks for the answer. At time I use the FindChildByXPath() function, it's seems to work in every situation for me.  The return object is different to FindChild() function, but it's ok.

       

      Regards, 

       

      APX