Forum Discussion

JeanL's avatar
JeanL
Contributor
13 years ago

SPAN tag without text

How can I reach SPAN tag which has no text in it:



HTML:



<DIV id="main_panel">

    <SPAN class="someclass"></SPAN>

    <SPAN class="status_error"></SPAN>

    <SPAN class="someotherclass"></SPAN>

</DIV>



<DIV id="main_panel_2">

    <SPAN class="someclass"></SPAN>

    <SPAN class="status_error"></SPAN>

    <SPAN class="someotherclass"></SPAN>

</DIV>



<DIV id="main_panel_3">

    <SPAN class="someclass"></SPAN>

    <SPAN class="status_error"></SPAN>

    <SPAN class="someotherclass"></SPAN>

</DIV>



I would like to get the SPAN object which is inside the DIV "main_panel" and which class is "status_error". Class of the SPAN can also be "status_ok", and that's what i would like to check, which one it is. I have tried this:



Set object = page.Panel("main_panel")



propArray = Array("tagName", "className")

valuesArray = Array("SPAN", "status_*")



Set temp = page.FindChild(propArray, valuesArray, 100)



If StrComp(temp.className, "status_error", 1) = 0 Then ...



FindChild returns nothing. I guess it's because the SPAN doesn't have any text in it, am I right? I can't use firstchild, lastchild etc. properties because the number of child elements of the DIV and the place of the SPAN object I need  varies.



So how can I check is the class of the SPAN "status_error" or "status_ok"?

3 Replies

  • Hi,



    Here's how you can do this:



    Set object = page.Panel("main_panel")

    arr = Split(object.innerHTML, "status_")

    result = Split(arr1(1), ">")

    Log.Message result(0)





    Refer to the 'Split Function' MSDN article for more information about the function.
  • Ok, this looks bit like MacGyver solution ;)



    I could also just use InStr method to compare innerHTML property of the object  to "status_error" or "status_ok", but i was looking for some "cleaner" way to do this.



    So there's no way to get the SPAN object I want with any find methods?
  • Hi Jean, 



    Here's how you can retrieve the value of the 'class' attribute using TC 8.50 and its new functionality to get web pages' elements using XPath:




    arr = page.EvaluateXPath("//DIV[@id='main_panel']/SPAN[starts-with(@class, 'status_')]/@class")
     

    Log.Message arr(0).NodeValue
     



    See the Page.EvaluateXPath help topic for more information.