Search code examples
rubywatirpage-object-gem

Can I identify element having an attribute_name containing a hyphen


HTML code:

<div class="Dashboard_Widget_Toolbar_Item disabled" data-widgetclientimplementation="Widget_Favorites">
  <img class="Dashboard_Widget_Toolbar_ItemImg" src="/WebCommon/Images/16x16_star.png">
  <div class="Dashboard_Widget_Toolbar_ItemName">Favorites</div>
  <div class="Dashboard_Widget_Toolbar_ItemDescrip">Shows items you have pinned from various applications</div>
</div>

Question

(knowing that I am using the Page-Object gem) Is it possible to identify a element by an attribute_name that contains a hyphen? In my example, ideally I wanted to identify an element as:

self.div(:favorites_toolbar_item, data-widgetclientimplementation: "Widget_Favorites")

From browsing I believe the answer might rely on css selector? but I could not find any relevant info to try.

Thanks JFF


Solution

  • Watir (and Page-Object) have support for data-* and aria-* attributes. You simply need to replace the dashes with underscores in the locator:

    self.div(:favorites_toolbar_item, data_widgetclientimplementation: "Widget_Favorites")