-1

我想使用 SitePrsim 创建页面对象。页面上元素的选择器采用“service_id”形式。如何在单个页面中查找 id 不同但选择器包含关键字“service_”的所有元素/部分?

我努力了:

class ServicesSection < SitePrism::Section
end

class APIs < SitePrism::Page
  element :create_service, '#content > a'
  sections :services, ServicesSection, "#service"

  def create_new
    create_service.click
  end
end

我正在寻找的元素如下所示:

<section class="service-widget u-legacy-cookie is-closed"    id="service_2555417736137">

所有这些元素都是来自:

<div class="self_clear" id="content">
4

1 回答 1

2

您可以使用 CSS“开始于”属性选择器来完成您的要求 - https://www.w3schools.com/css/css_attribute_selectors.asp

sections :services, ServicesSection, 'section[id^="service_"]'

但是,从您的示例中,仅使用类名也可以正常工作

sections :services, ServicesSection, 'section.service-widget' 
于 2017-05-22T16:16:59.627 回答