如何获取page_object元素的attribute_value?

时间:2012-12-13 11:45:02

标签: ruby cucumber watir-webdriver pageobjects page-object-gem

想象一下,我有一个像这样的图像:

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

获得其类值的方法可以是:

image_status = the_image.attribute_value('class')

确定。我正在使用page_object gem,假设我将图像作为元素,例如:

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

要获取attribute_value,我可以使用:

image_status = the_image_element.attribute_value('class')

...但我得到了一份弃权警告:

*** 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.

如何使用page_object元素获取class值?当然答案很简单,但我没有找到它。你能告诉我的方式吗?

提前谢谢!

1 个答案:

答案 0 :(得分:5)

如果您使用的是最新版本的Page-Object和Watir(分别为v2.2.1和v6.7.3),则attribute_value将不再提供弃用警告。支持#attribute#attribute_value

对于旧版本的Page-Object,您需要使用#attribute方法:

image_status = the_image_element.attribute('class')