5

Imagine i have a image like:

the_image = @browser.image(:id, 'image01')

The way to get the value of its class could be:

image_status = the_image.attribute_value('class')

Ok. I'm using page_object gem and lets suppose i have the image as element, like:

image(:the_image, :id => 'image01')

To get the attribute_value i can use:

image_status = the_image_element.attribute_value('class')

...but i get a DEPRECATION WARNING:

*** DEPRECATION WARNING
*** You are calling a method named attribute_value at page.rb:68:in `get_status'.
*** This method does not exist in page-object so it is being passed to the driver.
*** This feature will be removed in the near future.

How can i get the class value using the page_object element? Sure the answer is easy but i didn't found it. Can you please tell me the way?

Thank you in advance!

Pablo Gómez
  • 621
  • 1
  • 8
  • 18
  • The error is not shown in context of your page object class. Maybe you can add more to the question? – Dave McNulla Dec 14 '12 at 14:15
  • Hi Dave! There were no error, just and only the Warning. In fact, the method works correctly. The problem is that i didn't know how get the attribute value using page object natively. Justin Ko gives me the answer with: `yourelement_element.attribute('attribute_type')` – Pablo Gómez Dec 16 '12 at 21:56

1 Answers1

5

If you are using the latest versions of Page-Object and Watir (v2.2.1 and v6.7.3 respectively), the attribute_value will no longer give a deprecation warning. Both #attribute and #attribute_value are supported.

For older version of Page-Object, you need to use the #attribute method:

image_status = the_image_element.attribute('class')
Justin Ko
  • 46,526
  • 5
  • 91
  • 101
  • You're absolutely right. I googled and search on the Cheezy book and didn't find anything. Also looked on the Cheezy Rubydoc info but it seems i didn't search correctly... I'll triple check next time; thanks for the answer! – Pablo Gómez Dec 13 '12 at 14:32
  • Yout link is unfirtunately broken – sebisnow Aug 25 '17 at 09:41
  • Thanks @SSchneid. I have removed the link. The method is no longer directly defined in the Page-Object gem. It is now being delegated to the underlying `Watir::Element`. – Justin Ko Aug 25 '17 at 12:35