Ruby 检查Site Prism中的节是否具有特定类型的类
在ruby中使用Capybara并使用Site Prism创建页面对象。 Http元素如下所示:Ruby 检查Site Prism中的节是否具有特定类型的类,ruby,selenium,capybara,site-prism,Ruby,Selenium,Capybara,Site Prism,在ruby中使用Capybara并使用Site Prism创建页面对象。 Http元素如下所示: <section class='service-widget' id='service_id> <div class='title'> ... </div> <div class='content> ... </div> </section> 。。。 我已为此部分创建了类: class ServicesSect
<section class='service-widget' id='service_id>
<div class='title'> ... </div>
<div class='content> ... </div>
</section>
。。。
我已为此部分创建了类:
class ServicesSection < SitePrism::Section
end
class服务部分
然后将节添加到页面对象:
class ServicesPage < SitePrism::Page
sections :services, ServicesSection, 'section[id^="service_"]'
end
class-ServicesPage
这个元素可以折叠,唯一能指示它的状态的东西(如果它折叠或不折叠)是它的类名,它的类名从
<section class='service-widget' id='service_id>
如何确定此元素是否已折叠(关闭)?在ServiceSection I定义的方法中:
def closed?
root_element[:class].include? 'is-closed'
end
如果“已关闭”是类的一部分,则返回true。在ServiceSection I定义的方法中:
def closed?
root_element[:class].include? 'is-closed'
end
如果“已关闭”是类的一部分,则返回true。您对
根元素[:class]的自我回答。是否包括?“is closed“
可能对您的情况很好,但并不健壮,因为它还将匹配一个元素,该元素的类为is closed(明天关闭)
。更稳健的解决方案如下:
root_element.matches_css?('.is-closed', wait: false)
您对
根元素[:class]的自我回答。是否包括?“is closed“
可能对您的情况很好,但并不健壮,因为它还将匹配一个元素,该元素的类为is closed(明天关闭)
。更稳健的解决方案如下:
root_element.matches_css?('.is-closed', wait: false)
感谢您指出
根元素
——这不在SitePrism自述文件中;)感谢您指出根元素
——这不在SitePrism自述文件中;)