0

Using Capybara in ruby and creating page objects with Site Prism. Http element looks like this:

<section class='service-widget'  id='service_id>
   <div class='title'> ... </div>
   <div class='content> ... </div>
</section>

I have created class for this section:

class ServicesSection < SitePrism::Section
end

and then added section to the page object:

class ServicesPage < SitePrism::Page
    sections :services, ServicesSection, 'section[id^="service_"]'
end

This element can be collapsed and only thing that indicates state of it(if it is collapsed or not) is it's class name which is changed from

<section class='service-widget'  id='service_id>

to

<section class='service-widget is-closed'  id='service_id>

How to find out that this element is collapsed(closed) or not?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jakub Smolar
  • 81
  • 10

2 Answers2

2

Inside ServiceSection I defined method:

def closed?
   root_element[:class].include? 'is-closed'
end

This returns true if 'is-closed' is part of class.

Jakub Smolar
  • 81
  • 10
2

Your self-answer of root_element[:class].include? 'is-closed' will probably work just fine for your case, but isn't robust since it would also match an element with a class of is-closed-tomorrow. A more robust solution would be the following:

root_element.matches_css?('.is-closed', wait: false)
Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78