Mahbub Rahman Mahbub Rahman - 2 months ago 21
Groovy Question

Spock: Select visible elements

I have the html in my Page:

enter image description here

I have the content defined as:

child_criteria(wait: true) { $("div",class:"childSelectInIndex").find("ul",class:"oldSelectIndex") }


trying to select only the number of visible element those do not have
style="dsplay:none"

with :

def displayedchild_count = child_criteria.find("li",class:"targetChildAgeForm").not("li",class:"targetChildAgeForm",style:"display:none;").size()


But
println displayedchild_count
always show the size as 4.

How I can select the size of visible elements?

Answer

You should be able to do:

def visibleLis = $("div.childSelectInIndex ul.oldSelectIndex li.targetChildAgeForm")
                      .findAll { it.displayed }